public static Stream Decrypt128Stream(Stream Data, byte[] Key)
{
AesCryptoServiceProvider AES = null;
CryptoStream CS = null;
try
{
//Get the IV and length corrected Key.
KeyData KeyData = GenerateKeyIV128(Key);
//Create the AES crytpograhy object.
AES = new AesCryptoServiceProvider { BlockSize = 128, KeySize = 128, Key = KeyData.Key, IV = KeyData.IV, Mode = CipherMode.CBC, Padding = PaddingMode.PKCS7 };
CS = new CryptoStream(Data, AES.CreateDecryptor(), CryptoStreamMode.Read);
var D = new byte[CS.Length];
CS.Read(D, 0, (int)CS.Length - 1);
return new MemoryStream(D);
}
finally
{
if (AES != null) AES.Clear();
if (CS != null) CS.Dispose();
}
}