CryptoStream.Read Method

Reads a sequence of bytes from the current CryptoStream and advances the position within the stream by the number of bytes read.

Namespace: System.Security.Cryptography
Assembly: mscorlib (in mscorlib.dll)

virtual int Read (
	[InAttribute] [OutAttribute] array<unsigned char>^ buffer, 
	int offset, 
	int count
) override
public int Read (
	/** @attribute InAttribute() */ /** @attribute OutAttribute() */ byte[] buffer, 
	int offset, 
	int count
public override function Read (
	buffer : byte[], 
	offset : int, 
	count : int
) : int



An array of bytes. A maximum of count bytes are read from the current stream and stored in buffer.


The byte offset in buffer at which to begin storing the data read from the current stream.


The maximum number of bytes to be read from the current stream.

Return Value

The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero if the end of the stream has been reached.

Exception typeCondition


The CryptoStreamMode associated with current CryptoStream object does not match the underlying stream. For example, this exception is thrown when using Read with an underlying stream that is write only.


The offset parameter is less than zero.


The count parameter is less than zero.


Thesum of the count and offset parameters is longer than the length of the buffer.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0