Skip to content

Custom Encryption

To create a custom encryption algorithm you need to inherit from the TDataEncryption abstract class and override both the Encrypt(...) and Decrypt(...) methods.

Each method has a single string argument and returns another string argument, which can either be the decrypted message or the encrypted message.

[Title("My Custom Encryption")]
[Category("My Custom Encryption")]

[Image(typeof(IconCubeSolid), ColorTheme.Type.Yellow)]
[Description("Uses my own custom and super-secret encryption algorithm")]

[Serializable]
public class EncryptionMyCustom : TDataEncryption
{
    public override string Encrypt(string input)
    {
        // Logic for taking the input and returning it as an encrypted output
    }

    public override string Decrypt(string input)
    {
        // Logic for taking the input and returning it as an decrypted output
    }
}

The Title and Description attributes allow to define the name and give a brief description of what this encryption algorithm does, so it can be easily identified when choosing it from the Setting's dropdown menu.

The Image attribute determines the visual icon from the dropdown menu.

The Category attribute determines the location in the dropdown menu.

The TDataEncryption class has two abstract methods that need to be overridden and implemented in order to use the custom encryption.

  • Encrypt(input): Takes an input string and returns the encrypted value.
  • Decrypt(input): Takes an input string and returns the decrypted value.

Note that you can add serializable methods to the class and these values will appear in the Settings menu. For example, if your encryption algorithm requires a private string key called privateKey and an integer number called salt you can add them inside your class with the serialized attribute:

[SerializeField] private string privateKey;
[SerializeField] private int salt;