protected override void Dispose(bool disposing)
 {
     if (this.IsDisposed)
     {
         return;
     }
     try
     {
         if (!disposing)
         {
             return;
         }
         if (!this.finalBlockTransformed && this.Transform != null)
         {
             this.FlushFinalBlock();
         }
         (this.baseStream as OperationStream)?.Dispose();
     }
     finally
     {
         try
         {
             this.finalBlockTransformed = true;
             if (this.Transform != null)
             {
                 this.Transform.Dispose();
             }
             if (this.inputBuffer != null)
             {
                 Array.Clear((Array)this.inputBuffer, 0, this.inputBuffer.Length);
             }
             if (this.outputBuffer != null)
             {
                 Array.Clear((Array)this.outputBuffer, 0, this.outputBuffer.Length);
             }
             this.inputBuffer    = (byte[])null;
             this.outputBuffer   = (byte[])null;
             this.blockTransform = (IBlockTransform)null;
             this.baseStream     = (Stream)null;
         }
         finally
         {
             this.IsDisposed = true;
             base.Dispose(disposing);
         }
     }
 }
Exemple #2
0
        public CFBMode(byte[] iv, IBlockTransform blockTransform, bool encryption, int paddingSizeInBytes)
            : base(iv, blockTransform.BlockSizeInBytes, paddingSizeInBytes)
        {
            if (iv == null)
            {
                throw new ArgumentNullException(nameof(iv));
            }
            if (iv.Length != blockTransform.BlockSizeInBytes)
            {
                throw new ArgumentOutOfRangeException(nameof(iv));
            }

            this.FR  = CryptoPool.Rent(iv.Length);
            this.FRE = CryptoPool.Rent(iv.Length);
            iv.CopyTo(this.FR, 0);

            this.blockTransform = blockTransform;
            this.encryption     = encryption;
        }
Exemple #3
0
 public ECBMode(IBlockTransform blockTransform, int paddingSizeInBytes)
     : base(Array.Empty <byte>(), blockTransform.BlockSizeInBytes, paddingSizeInBytes)
 {
     this.blockTransform = blockTransform;
 }
 protected override byte[] Transform(IBlockTransform encryptor, byte[] data)
 {
     return encryptor.DecryptBlock(data);
 }
 public Decryptor(IBlockTransform encryptor, int blockSize, int outputSize)
     : base(encryptor, blockSize, outputSize)
 { }
 protected virtual byte[] Transform(IBlockTransform encryptor, byte[] data)
 {
     return encryptor.EncryptBlock(data);
 }
 public Encryptor(IBlockTransform encryptor, int blockSize, int outputSize)
 {
     _encryptor = encryptor;
     _blockSize = blockSize;
     _outputSize = outputSize;
 }
 protected override byte[] Transform(IBlockTransform encryptor, byte[] data)
 {
     return(encryptor.DecryptBlock(data));
 }
 public Decryptor(IBlockTransform encryptor, int blockSize, int outputSize)
     : base(encryptor, blockSize, outputSize)
 {
 }
 protected virtual byte[] Transform(IBlockTransform encryptor, byte[] data)
 {
     return(encryptor.EncryptBlock(data));
 }
 public Encryptor(IBlockTransform encryptor, int blockSize, int outputSize)
 {
     _encryptor  = encryptor;
     _blockSize  = blockSize;
     _outputSize = outputSize;
 }