SteamKit2.CryptoHelper.AESDecrypt C# (CSharp) Method

AESDecrypt() public static method

Decrypts an input byte array using AES/CBC/PKCS7 with a given key and IV
public static AESDecrypt ( byte input, byte key, byte iv ) : byte[]
input byte
key byte
iv byte
return byte[]
        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;
            }
        }