Пример #1
0
        /// <summary>Clean direct buffer pool</summary>
        private void CleanBufferPool()
        {
            ByteBuffer buf;

            while ((buf = bufferPool.Poll()) != null)
            {
                CryptoStreamUtils.FreeDB(buf);
            }
        }
Пример #2
0
 /// <exception cref="System.IO.IOException"/>
 public CryptoInputStream(InputStream @in, CryptoCodec codec, int bufferSize, byte
                          [] key, byte[] iv, long streamOffset)
     : base(@in)
 {
     // Underlying stream offset.
     CryptoStreamUtils.CheckCodec(codec);
     this.bufferSize       = CryptoStreamUtils.CheckBufferSize(codec, bufferSize);
     this.codec            = codec;
     this.key              = key.MemberwiseClone();
     this.initIV           = iv.MemberwiseClone();
     this.iv               = iv.MemberwiseClone();
     this.streamOffset     = streamOffset;
     isByteBufferReadable  = @in is ByteBufferReadable;
     isReadableByteChannel = @in is ReadableByteChannel;
     inBuffer              = ByteBuffer.AllocateDirect(this.bufferSize);
     outBuffer             = ByteBuffer.AllocateDirect(this.bufferSize);
     decryptor             = GetDecryptor();
     ResetStreamOffset(streamOffset);
 }
Пример #3
0
 /// <exception cref="System.IO.IOException"/>
 public CryptoOutputStream(OutputStream @out, CryptoCodec codec, int bufferSize, byte
                           [] key, byte[] iv, long streamOffset)
     : base(@out)
 {
     // Underlying stream offset.
     CryptoStreamUtils.CheckCodec(codec);
     this.bufferSize   = CryptoStreamUtils.CheckBufferSize(codec, bufferSize);
     this.codec        = codec;
     this.key          = key.MemberwiseClone();
     this.initIV       = iv.MemberwiseClone();
     this.iv           = iv.MemberwiseClone();
     inBuffer          = ByteBuffer.AllocateDirect(this.bufferSize);
     outBuffer         = ByteBuffer.AllocateDirect(this.bufferSize);
     this.streamOffset = streamOffset;
     try
     {
         encryptor = codec.CreateEncryptor();
     }
     catch (GeneralSecurityException e)
     {
         throw new IOException(e);
     }
     UpdateEncryptor();
 }
Пример #4
0
 /// <exception cref="System.IO.IOException"/>
 public CryptoInputStream(InputStream @in, CryptoCodec codec, int bufferSize, byte
                          [] key, byte[] iv)
     : this(@in, codec, bufferSize, key, iv, CryptoStreamUtils.GetInputStreamOffset(@in
                                                                                    ))
 {
 }
Пример #5
0
 /// <summary>Forcibly free the direct buffers.</summary>
 private void FreeBuffers()
 {
     CryptoStreamUtils.FreeDB(inBuffer);
     CryptoStreamUtils.FreeDB(outBuffer);
     CleanBufferPool();
 }
Пример #6
0
 /// <exception cref="System.IO.IOException"/>
 public CryptoInputStream(InputStream @in, CryptoCodec codec, byte[] key, byte[] iv
                          )
     : this(@in, codec, CryptoStreamUtils.GetBufferSize(codec.GetConf()), key, iv)
 {
 }
Пример #7
0
 /// <exception cref="System.IO.IOException"/>
 public CryptoOutputStream(OutputStream @out, CryptoCodec codec, byte[] key, byte[]
                           iv, long streamOffset)
     : this(@out, codec, CryptoStreamUtils.GetBufferSize(codec.GetConf()), key, iv, streamOffset
            )
 {
 }