Cryptography - SebastianKErben/SKE.Unity3D GitHub Wiki
The Cryptography namespace contains the static class Crypto, which provides methods for encrypting data via Rijndael. You can encrypt data by using one of the following methods:
Crypto.Encrypt(byte[] rawData)
Crypto.Encrypt(int rawData)
Crypto.Encrypt(string rawData)
Each of those methods will return a byte array containing the encrypted data. Additionally, a second string parameter can be used for setting a custom salt phrase like
var myEncryptedData =
Crypto.Encrypt("Let's encrypt this secret message", "with a special salt");
The class also provides methods to decrypt data:
Crypto.Decrypt(byte[] encryptedData)
Crypto.DecryptInt32(byte[] encryptedData)
Crypto.DecryptUTF8String(byte[] encryptedData)
Those methods can also take a second string parameter for using the custom salt if one has been used when encrypting
var decryptedData = Crypto.DecryptUTF8String(myEncryptedData, "with a special salt");
Furthermore, Crypto contains a property
Crypto.RandomHash
to will return a different integer value each time it is called.
Additonally, the Cryptography namespace contains a sub namespace Utils which contains two classes.
HighscoreTracker is derived from SingletonEternal and aims to provide a singleton for tracking of one highscore value. The tracking happens by using multiple sub variables that are changed in a way so that the end result will always reflect the real highscore value. The reason for this is to make it harder to manipulate the highscore value by changing a single value via direct memory access from outside.
To add a value to the highscore, just call
HighscoreTracker.Instance.Add(int score)
Get the current score with the property
HighscoreTracker.Instance.ScoreTotal
The second class in the Utils namespace is SecureStore, which is also derived from SingletonEternal. This singleton aims to provide an encrypted store for important integer values.
To add a value to the store, simply call
SecureStore.Instance.Store(string name, int value)
which will return you an integer key. This key is important for getting the value back or adding to it so you need to store it in a variable.
To get a value from the store, call
SecureStore.Instance.Get(string name, int key)
This will return the value from the store and at the same time delete the value from it. Since you may want to add to the value, the class also provides
SecureStore.Instance.Add(string name, int key, int value)
where value is the number you want to add to the already existing value.
You can take a look at Editor/Tests/Cryptography for some example code (although you need to keep in mind that the functionality of the singleton classes is actually implemented in subclasses for testing purposes).