public static string Decrypt(string text, string hash) { CryptLib _crypt = new CryptLib(); String iv = String.Join("", text.Reverse().Take(16).Reverse()); text = text.Remove(text.Length - 16); return(_crypt.decrypt(text, hash, iv)); }
private static void Main(string[] args) { string text = "Simple text"; String iv = CryptLib.GenerateRandomIV(16); string key = CryptLib.getHashSha256("Your key", 32); text = CryptLib.Encrypt(text, key, iv); Console.WriteLine(text); Console.WriteLine(CryptLib.Decrypt(text, key)); }
/** * This function generates random string of the given input length. * * @param _plainText * Plain text to be encrypted * @param _key * Encryption Key. You'll have to use the same key for decryption * @return returns encrypted (cipher) text */ public static string Encrypt(string text, string hash, String iv) { CryptLib _crypt = new CryptLib(); return(_crypt.encrypt(text, hash, iv) + iv); }