-
Notifications
You must be signed in to change notification settings - Fork 1
Encryption Providers
The Pixel Security Toolkit includes a number of providers to provide encryption and hashing in your games. You can use them without connecting any Toolkit modules.
Current Providers List:
- AES Encryption;
- DES Encryption;
- XOR Encryption;
- Base64 Converter;
- MD5 Hash Module;
- SHA1/SHA256/SHA512 Hash Modules;
- RSA Encryption;
- xxHash Module;
Any provider include encryption class based on IDataEncryption interface and may be initialized as separated object:
AES provider = new AES(new AES.EncryptionOptions
{
/* Provider Options */
});
After initialization you can encrypt / decrypt any string or byte array:
provider.EncodeString(PLANE_STRING);
provider.DecodeString(ENCRYPTED_STRING);
This modules provide AES algorythm realisation.
Available Options in Constructor:
- Password(string) - AES Password for encryption/decryption;
- BufferKeySize(string) - AES Buffer Size. By default 32;
- BlockSize(string) - AES BlockSize for encryption/decryption. By default 256;
- KeySize(string) - AES KeySize for encryption/decryption. By default 256;
Available Methods:
- EncodeString(string) - Returns DES string based on plane string;
- EncodeBinary(byte[]) - Returns DES byte array based on user byte array;
- DecodeString(string) - Returns string value from DES string;
- DecodeBinary(byte[]) - Return byte array from DES byte array;
This modules provide DES algorythm realisation.
Available Options in Constructor:
- Password(string) - DES Password for encryption/decryption;
Available Methods:
- EncodeString(string) - Returns DES string based on plane string;
- EncodeBinary(byte[]) - Returns DES byte array based on user byte array;
- DecodeString(string) - Returns string value from DES string;
- DecodeBinary(byte[]) - Return byte array from DES byte array;
This modules provide XOR algorythm realisation. You can only encrypt and decrypt string data.
Available Options in Constructor:
- Password(string) - XOR Password for encryption/decryption;
Available Methods:
- EncodeString(string) - Returns XOR string based on plane string;
- EncodeBinary(byte[]) - Not available for XOR algorythm;
- DecodeString(string) - Returns string value from XOR string;
- DecodeBinary(byte[]) - Not available for XOR algorythm;
This modules provide Base64 algorythm realisation.
Available Options in Constructor: No options provided
Available Methods:
- EncodeString(string) - Returns Base64 string based on plane string;
- EncodeBinary(byte[]) - Returns Base64 byte array based on user byte array;
- DecodeString(string) - Returns string value from Base64 string;
- DecodeBinary(byte[]) - Return byte array from Base64 byte array;
This modules provide MD5 algorythm realisation. You can only encrypt data, without decryption.
Available Options in Constructor: No options provided
Available Methods:
- EncodeString(string) - Returns MD5 string based on plane string;
- EncodeBinary(byte[]) - Returns MD5 byte array based on user byte array;
- DecodeString(string) - Not allowed for Hashes;
- DecodeBinary(byte[]) - Not allowed for Hashes;
This modules provide SHA1/SHA256/SHA512 algorythm realisation. You can only encrypt data, without decryption.
Available Options in Constructor: No options provided
Available Methods:
- EncodeString(string) - Returns SHA1/SHA256/SHA512 string based on plane string;
- EncodeBinary(byte[]) - Returns SHA1/SHA256/SHA512 byte array based on user byte array;
- DecodeString(string) - Not allowed for Hashes;
- DecodeBinary(byte[]) - Not allowed for Hashes;
This modules provide RSA algorythm realisation.
Available Options in Constructor:
- PublicKey(string) - Public Key. By default RSAPublicKey;
- PrivateKey(string) - Private Key. By default RSAPrivateKey;
Available Methods:
- EncodeString(string) - Returns RSA string based on plane string;
- EncodeBinary(byte[]) - Returns RSA byte array based on user byte array;
- DecodeString(string) - Returns string value from RSA string;
- DecodeBinary(byte[]) - Return byte array from RSA byte array;
This module provide xxHash algorythm realisation. You can only encrypt data, without decryption.
Available Options in Constructor:
- PRIME32_1(uint) - Prime block #1. By default 2654435761U;
- PRIME32_2(uint) - Prime block #2. By default 2246822519U;
- PRIME32_3(uint) - Prime block #3. By default 3266489917U;
- PRIME32_4(uint) - Prime block #4. By default 668265263U;
- PRIME32_5(uint) - Prime block #5. By default 374761393U;
- Length(int) - Length of hash. By default = 16;
- Seed(uint) - Seed value. By default = 0;
Available Methods:
- EncodeString(string) - Returns xxHash string based on plane string;
- EncodeBinary(byte[]) - Returns xxHash byte array based on user byte array;
- DecodeString(string) - Not allowed for Hashes;
- DecodeBinary(byte[]) - Not allowed for Hashes;
To produce your own provider you can create a new provider class in "Assets/PixelSecurity/Core/Encryption" folder based on IDataEncryption interface:
namespace PixelSecurity.Core.Encryption
{
public class YourEncryptionProvider : IDataEncryption
{
// Provider Constructor
public YourEncryptionProvider(){}
// Encrypt String
public string EncodeString(string plane)
{
string encodedText = plane;
return encodedText;
}
// Encrypt Byte Array
public byte[] EncodeBinary(byte[] src)
{
byte[] encodedBytes = src;
return encodedBytes;
}
// Decrypt String
public string DecodeString(string encrypted)
{
string decodedText = encrypted;
return decodedText;
}
// Decrypt Byte Array
public byte[] DecodeBinary(byte[] src)
{
byte[] decodedBytes = src;
return decodedBytes;
}
}
}
2023 (C) Developed by TinyPlay Games. Provided under MIT License.