Exemple #1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _impl.Dispose();
     }
 }
        public async Task <Stream> OpenReadAsync(CancellationToken ct)
        {
            Stream stream = null;

            System.Security.Cryptography.Aes aes = null;
            ICryptoTransform decryptor           = null;

            try
            {
                stream = await _fileInfo.OpenReadAsync(ct);

                var header = await AesHeader.ReadAsync(stream, ct);

                aes = CreateAes(header.Version);
                var key = FileSystem.ComputeKey(header.IV, header.Version);
                decryptor = CreateTransform(aes, key, header.IV, AesMode.Decrypt); // disposed by CryptoStream
                return(new CryptoStream(stream, decryptor, CryptoStreamMode.Read));
            }
            catch
            {
                decryptor?.Dispose();
                stream?.Dispose();
                throw;
            }
            finally
            {
                aes?.Dispose();
            }
        }
        private bool disposedValue = false; // To detect redundant calls

        void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _cryptor.Dispose();
                    _cryptor = null;
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }