System.Utilities.Cryptography.Encryption.Decrypt256Stream C# (CSharp) Method

Decrypt256Stream() public static method

Decrypts the specified data using a 256-bit cipher. The key can be any length.
public static Decrypt256Stream ( Stream Data, byte Key ) : Stream
Data Stream The data to be decrypted.
Key byte The key used to decrypt the data.
return Stream
        public static Stream Decrypt256Stream(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 = 256, KeySize = 256, 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();
            }
        }

Same methods

Encryption::Decrypt256Stream ( byte Data, byte Key ) : Stream