public static byte[] EncryptData(CryptoKey cryptoKey, CryptoIV cryptoIV, byte[] data) { // Advanced Encryption Standard ICryptoTransform encryptor = new RijndaelManaged().CreateEncryptor(cryptoKey, cryptoIV); using (MemoryStream stream = new MemoryStream()) { using (CryptoStream cryptoStream = new CryptoStream(stream, encryptor, CryptoStreamMode.Write)) { cryptoStream.Write(data, 0, data.Length); cryptoStream.FlushFinalBlock(); return stream.ToArray(); } } }
public static byte[] EncryptData(byte[] data, out CryptoKey cryptoKey, out CryptoIV cryptoIV) { cryptoKey = new CryptoKey(); cryptoIV = new CryptoIV(); return EncryptData(cryptoKey, cryptoIV, data); }
public static ICryptoTransform CreateEncryptor(this SymmetricAlgorithm symmetricAlgorithm, CryptoKey cryptoKey, CryptoIV cryptoIV) { return symmetricAlgorithm.CreateEncryptor(cryptoKey.Value, cryptoIV.Value); }