예제 #1
0
            public CryptCarotDAV_CryptStream(CryptCarotDAV crypter, Stream baseStream, long?streamLength = null) : base()
            {
                innerStream       = new HashStream(baseStream, new SHA256CryptoServiceProvider());
                innerStreamLength = streamLength ?? innerStream.Length;

                Array.Copy(_salt, header, 24);

                aes           = new AesCryptoServiceProvider();
                aes.BlockSize = BlockSize;
                aes.KeySize   = KeySize;
                aes.Mode      = CipherMode.CBC;
                aes.Padding   = PaddingMode.Zeros;

                aes.Key   = crypter.Key;
                aes.IV    = crypter.IV;
                encryptor = aes.CreateEncryptor();

                cryptStream = new CryptoStream(innerStream, encryptor, CryptoStreamMode.Read);
                if (innerStreamLength > 0)
                {
                    patlen = (int)((innerStreamLength - 1) % BlockSizeByte + 1);
                }
                else
                {
                    patlen = BlockSizeByte;
                }
                cryptlen = innerStreamLength + BlockSizeByte - patlen;
            }
예제 #2
0
            protected override void Dispose(bool isDisposing)
            {
                base.Dispose(isDisposing);
                if (!disposed)
                {
                    if (isDisposing)
                    {
                        innerStream?.Dispose();
                        cryptStream?.Dispose();
                    }

                    innerStream = null;
                    cryptStream = null;

                    disposed = true;
                }
            }