/// <summary> /// AESs the encrypt. /// </summary> /// <param name="pTextToEncrypt">The text to encrypt</param> /// <param name="pPassPhrase">The pass phrase</param> /// <param name="pInitVector">The init vector</param> /// <param name="hashAlgorithm">The hashing algorithm to use</param> /// <returns></returns> public static string AESEncrypt(string pTextToEncrypt, string pPassPhrase, string pInitVector, AESHashAlgorithm hashAlgorithm) { RijndaelEnhanced rijndaelKey = new RijndaelEnhanced(pPassPhrase, pInitVector, 4, 0, 128, hashAlgorithm.ToString()); return(rijndaelKey.Encrypt(pTextToEncrypt)); }
/// <summary> /// Overloaded. Decrypts a cipher block and returns the decrypted data. /// </summary> /// <param name="pTextToDecrypt"></param> /// <param name="pPassPhrase"></param> /// <param name="pInitVector"></param> /// <returns></returns> public static byte[] AESDecryptToBytes(byte[] pTextToDecrypt, string pPassPhrase, string pInitVector) { RijndaelEnhanced rijndaelKey = new RijndaelEnhanced(pPassPhrase, pInitVector); return(rijndaelKey.DecryptToBytes(pTextToDecrypt)); }
/// <summary> /// Encrypts a string using the AES algorithm and returns the /// base64 representation of that string. /// </summary> /// <param name="pTextToEncrypt"></param> /// <param name="pPassPhrase"></param> /// <param name="pInitVector"></param> /// <returns></returns> public static string AESEncrypt(string pTextToEncrypt, string pPassPhrase, string pInitVector) { RijndaelEnhanced rijndaelKey = new RijndaelEnhanced(pPassPhrase, pInitVector); return(rijndaelKey.Encrypt(pTextToEncrypt)); }