Beispiel #1
0
        public void Encrypt(Stream inStream, Stream outStream)
        {
            ICryptoTransform transform        = _wrappedAes.CreateEncryptor();
            long             originalPosition = outStream.Position;

            outStream.Write(BitConverter.GetBytes((Int32)_wrappedAes.IV.Length), 0, sizeof(Int32));
            outStream.Write(_wrappedAes.IV, 0, _wrappedAes.IV.Length);

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