예제 #1
0
        /// <summary>
        /// When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
        /// </summary>
        /// <param name="buffer">An array of bytes. This method copies <paramref name="count"/> bytes from <paramref name="buffer"/> to the current stream.</param>
        /// <param name="offset">The zero-based byte offset in <paramref name="buffer"/> at which to begin copying bytes to the current stream.</param>
        /// <param name="count">The number of bytes to be written to the current stream.</param>
        /// <exception cref="T:System.ArgumentException">The sum of <paramref name="offset"/> and <paramref name="count"/> is greater than the buffer length. </exception>
        /// <exception cref="T:System.ArgumentNullException">
        ///     <paramref name="buffer"/> is null. </exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///     <paramref name="offset"/> or <paramref name="count"/> is negative. </exception>
        /// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
        /// <exception cref="T:System.NotSupportedException">The stream does not support writing. </exception>
        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (!_init)
            {
                if (!CipherTextOnly)
                {
                    if (_encrypt)
                    {
                        _output.Write(_iv, 0, _iv.Length);
                    }
                    else
                    {
                        Array.Copy(buffer, 0, _iv, 0, _iv.Length);
                        offset = offset + _iv.Length;
                        count  = count - _iv.Length;
                    }
                }
                _initFunc(_iv, _cipher, _encrypt);
                _init = true;
            }

            var outBuffer = new byte[_cipher.GetUpdateOutputSize(count)];
            var outLen    = _cipher.ProcessBytes(buffer, offset, count, outBuffer, 0);

            _output.Write(outBuffer, 0, outLen);
            outBuffer.Clear();
            _outLen += outLen;
            _inLen  += count;
        }
예제 #2
0
 /// <summary>
 /// When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
 /// </summary>
 /// <param name="buffer">An array of bytes. This method copies <paramref name="count" /> bytes from <paramref name="buffer" /> to the current stream.</param>
 /// <param name="offset">The zero-based byte offset in <paramref name="buffer" /> at which to begin copying bytes to the current stream.</param>
 /// <param name="count">The number of bytes to be written to the current stream.</param>
 /// <exception cref="InvalidCryptoDataException"></exception>
 /// <exception cref="T:System.ArgumentException">The sum of <paramref name="offset" /> and <paramref name="count" /> is greater than the buffer length.</exception>
 /// <exception cref="T:System.ArgumentNullException"><paramref name="buffer" /> is null.</exception>
 /// <exception cref="T:System.ArgumentOutOfRangeException"><paramref name="offset" /> or <paramref name="count" /> is negative.</exception>
 /// <exception cref="T:System.IO.IOException">An I/O error occurs.</exception>
 /// <exception cref="T:System.NotSupportedException">The stream does not support writing.</exception>
 /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.</exception>
 public override void Write(byte[] buffer, int offset, int count)
 {
     try
     {
         Init();
         var outBuffer = new byte[_cipher.GetUpdateOutputSize(count)];
         var outLen    = _cipher.ProcessBytes(buffer, offset, count, outBuffer, 0);
         _output.Write(outBuffer, 0, outLen);
         outBuffer.Clear();
         _outLen += outLen;
         _inLen  += count;
     }
     catch (InvalidCipherTextException ex)
     {
         throw new InvalidCryptoDataException(ex.Message);
     }
 }
예제 #3
0
 public int GetUpdateOutputSize(int inputLen)
 {
     return(cipher.GetUpdateOutputSize(inputLen));
 }
예제 #4
0
 public int GetUpdateOutputSize(int inputLen)
 {
     return(bufferedCipher.GetUpdateOutputSize(inputLen));
 }