Esempio n. 1
0
        public void Decrypt(Stream inStream, Stream outStream)
        {
            byte[] ivLengthBytes = new byte[sizeof(Int32)];
            inStream.Read(ivLengthBytes, 0, ivLengthBytes.Length);
            Int32 ivLength = BitConverter.ToInt32(ivLengthBytes, 0);

            byte[] iv = new byte[ivLength];
            inStream.Read(iv, 0, ivLength);

            int count          = 0;
            int blockSizeBytes = _wrappedAes.BlockSize;

            byte[] data = new byte[blockSizeBytes];

            ICryptoTransform transform = _wrappedAes.CreateDecryptor(Key, iv);

            using (CryptoStream cryptoStream = new CryptoStream(outStream, transform, CryptoStreamMode.Write))
            {
                while ((count = inStream.Read(data, 0, blockSizeBytes)) > 0)
                {
                    cryptoStream.Write(data, 0, count);
                }
                cryptoStream.FlushFinalBlock();
                cryptoStream.Close();
            }
        }