Exemplo n.º 1
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);
 }
Exemplo n.º 2
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();
 }