EncryptionHelper - Aghyad-Khlefawi/Coddee GitHub Wiki

A static class containing a helper functions for encrypting and decrypting data.

Methods

Name Description
EncryptString(string,string,SymmetricAlgorithm) Encrypts a string using a symmetric algorithm and returns encrypted bytes
EncryptStringAsBase64(string,string,SymmetricAlgorithm) Encrypts a string using a symmetric algorithm and returns base64 string of the encrypted data
Decrypt(byte[],string,SymmetricAlgorithm) Decrypt bytes using a symmetric algorithm
Decrypt(string,string,SymmetricAlgorithm) Decrypt a base64 using a symmetric algorithm

C# Example:

//Encrypt to bytes
string plainText = "My Secret content";
string mySecretKey = "VERYSTRONGPASSWORD";
byte[] encryptedBytes = EncryptionHelper.EncryptString(plainText, mySecretKey);
string decryptedText = EncryptionHelper.Decrypt(encryptedBytes, mySecretKey);
Console.WriteLine(decryptedText); //outputs: My Secret content

//Encrypt to base64 string
string encryptedString = EncryptionHelper.EncryptStringAsBase64(plainText, mySecretKey);
decryptedText = EncryptionHelper.Decrypt(encryptedString, mySecretKey);
Console.WriteLine(decryptedText); //outputs: My Secret content