protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    switch (_mode)
                    {
                    case StrongCryptoStreamMode.Write:
                    {
                        if (_bufferIndex > 0)
                        {
                            StrongCryptoUtils.Encrypt(_buffer, _key, 0, _bufferIndex);
                            _stream.Write(_buffer, 0, _bufferIndex);
                            _bufferIndex = 0;
                        }
                    }
                    break;
                    }

                    _stream.Close();
                }

                _buffer = null;
                _stream = null;
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (!CanWrite)
            {
                throw new IOException(SR.StreamWriteNotSupported);
            }

            while (count > 0)
            {
                if (_bufferIndex == _blockSize)
                {
                    StrongCryptoUtils.Encrypt(_buffer, _key, 0, _bufferIndex);
                    _stream.Write(_buffer, 0, _bufferIndex);
                    _bufferIndex = 0;
                }

                int size = _blockSize - _bufferIndex;
                if (size > count)
                {
                    size = count;
                }

                Buffer.BlockCopy(buffer, offset, _buffer, _bufferIndex, size);

                count        -= size;
                offset       += size;
                _bufferIndex += size;
            }
        }