Skip to content

Latest commit

 

History

History
122 lines (99 loc) · 4.24 KB

README.md

File metadata and controls

122 lines (99 loc) · 4.24 KB

Unity Crypto Library

Unity Crypto Library
Unity Crypto Library is a set of free and open source cross-platform tools for using cryptographic and hash functions in your games. It also contains helper classes for handling files and web requests for your convenience.

I periodically update possible algorithms based on the latest research in crypto-graphy.

Note! This library supports only Unity 2021+ versions

Get Started

Unity Crypto Library is designed for your application and games security and using only default API's like System and UnityEngine.

Installation process:

Or Using Unity Package Manager:
https://github.com/DevsDaddy/UnityCrypto.git?path=/DevsDaddy/Shared/CryptoLibrary/

Usage

You can use a simple controller for fast encryption/decryption:

// Setup Default Crypto-Provider
CryptoController.SetDefaultProvider(new AESProvider(new AESEncryptionOptions {
    cryptoKey = "myCryptoKey"
}));

// Simple Plain-Text Encryption-Decryption 
string encryptedText = CryptoController.Encrypt("MyTextToEncrypt");
string decryptedText = CryptoController.Decrypt(encryptedText);

// Or with in-line crypto-provider
string encryptedText2 = CryptoController.Encrypt("TextToEncrypt", new AESProvider(new AESEncryptionOptions {
    cryptoKey = "myCryptoKey"
}));

Or initial crypto providers manually:*

// Create your provider
AESProvider provider = new AESProvider(new AESEncryptionOptions {
    cryptoKey = "myCryptoKey"
});

// Work with provider
string encryptedText = provider.EncryptString("MyTextToEncrypt");
string decryptedText = provider.DecryptString(encryptedText);

Also you can read/write files using util class (similar like CryptoController just for files):*

// Setup Default Crypto-provider for Files
CryptoFile.SetDefaultProvider(new AESProvider(new AESEncryptionOptions {
    cryptoKey = "key"
}));

// Read and Decrypt File
string decryptedText = CryptoFile.ReadText("path_to_encrypted_file");

// Encrypt plain-text and save to file
bool writtenFile = CryptoFile.WriteText("path_to_encrypted_file", decryptedText);

Crypto-Algorithms

Library contains popular crypto modules:

  • AES (Recommended);
  • Triple DES (Recommended);
  • BlowFish (Recommended);
  • Twofish (Recommended);
  • RSA (Recommended for Web);
  • DES;
  • Base64;
  • XOR (Only strings support, no byte array);

Code Sample:

string encrypted = CryptoController.Encrypt("TextToEncrypt", new AESProvider(new AESEncryptionOptions {
    cryptoKey = "myCryptoKey"
}));

// Return Encrypted
Debug.Log(encrypted);

Hashing

Library contains popular hashing functions:

  • SHA1 / SHA256 / SHA512 (Recommended);
  • PBKDF2 (Recommended);
  • MD5;
  • xxHash;
  • RIPEMD-160;
  • CRC32;

Code Sample:

string hashed = CryptoController.Encrypt("TextToEncrypt", new MD5Provider(new MD5EncryptionOptions { }));

// Return Hashed
Debug.Log(hashed);

Examples

See framework usage examples in other projects:

Coming Soon (TO-DO)

I plan to add the following functionality in the near future:

  • Sending and accepting encrypted HTTP requests and working with encrypted data on sockets with server examples on NodeJS / CSharp;
  • Read / Write files using chunks for large amounts of data;
  • New Hashing Modules: Argon2, BCrypt, SCrypt, Whirlpool;
  • New Encryption Modules like SPHINCS+;

Join Community

Support Me

You can support the development and updating of libraries and assemblies by dropping a coin:

Bitcoin (BTC)bc1qef2d34r4xkrm48zknjdjt7c0ea92ay9m2a7q55
Etherium (ETH)0x1112a2Ef850711DF4dE9c432376F255f416ef5d0
Boostyhttps://boosty.to/devsdaddy