System.Security.Cryptography.CryptoStream.ReadByte C# (CSharp) Method

ReadByte() public method

public ReadByte ( ) : int
return int
        public override int ReadByte()
        {
            // If we have enough bytes in the buffer such that reading 1 will still leave bytes
            // in the buffer, then take the faster path of simply returning the first byte.
            // (This unfortunately still involves shifting down the bytes in the buffer, as it
            // does in Read.  If/when that's fixed for Read, it should be fixed here, too.)
            if (_outputBufferIndex > 1)
            {
                byte b = _outputBuffer[0];
                Buffer.BlockCopy(_outputBuffer, 1, _outputBuffer, 0, _outputBufferIndex - 1);
                _outputBufferIndex -= 1;
                return b;
            }

            // Otherwise, fall back to the more robust but expensive path of using the base 
            // Stream.ReadByte to call Read.
            return base.ReadByte();
        }

Usage Example

Ejemplo n.º 1
0
        public byte[] Decrypt(byte[] cipher, byte[] key, byte[] IV)
        {
            System.Collections.Generic.List<byte> bytes = new List<byte>();

            using (AesManaged _aesAlgorithm = new AesManaged())
            {
                _aesAlgorithm.Key = key;
                _aesAlgorithm.IV = IV;

                using (ICryptoTransform decryptor = _aesAlgorithm.CreateDecryptor(_aesAlgorithm.Key, _aesAlgorithm.IV))
                {
                    using (System.IO.MemoryStream str = new System.IO.MemoryStream(cipher))
                    {
                        using (CryptoStream crypto = new CryptoStream(str, decryptor, CryptoStreamMode.Read))
                        {
                            int b = crypto.ReadByte();

                            while (b > -1)
                            {
                                b = crypto.ReadByte();
                                bytes.Add((byte)b);
                            }
                        }
                    }
                    _aesAlgorithm.Clear();
                }
            }

            return bytes.ToArray();
        }
All Usage Examples Of System.Security.Cryptography.CryptoStream::ReadByte