Ejemplo n.º 1
0
        /// <summary>Clean direct buffer pool</summary>
        private void CleanBufferPool()
        {
            ByteBuffer buf;

            while ((buf = bufferPool.Poll()) != null)
            {
                CryptoStreamUtils.FreeDB(buf);
            }
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 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
                                                                                    ))
 {
 }
Ejemplo n.º 5
0
 /// <summary>Forcibly free the direct buffers.</summary>
 private void FreeBuffers()
 {
     CryptoStreamUtils.FreeDB(inBuffer);
     CryptoStreamUtils.FreeDB(outBuffer);
     CleanBufferPool();
 }
Ejemplo n.º 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)
 {
 }
Ejemplo n.º 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
            )
 {
 }