public static byte[] AESDecrypt( byte[] input, byte[] key, byte[] iv )
{
using ( var aes = new RijndaelManaged() )
{
aes.BlockSize = 128;
aes.KeySize = 128;
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.PKCS7;
byte[] plainText = new byte[ input.Length ];
int outLen = 0;
using ( var aesTransform = aes.CreateDecryptor( key, iv ) )
using ( var ms = new MemoryStream( input ) )
using ( var cs = new CryptoStream( ms, aesTransform, CryptoStreamMode.Read ) )
{
outLen = cs.Read( plainText, 0, plainText.Length );
}
byte[] output = new byte[ outLen ];
Array.Copy( plainText, 0, output, 0, output.Length );
return output;
}
}