Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Security.​Cryptography.​CryptoStream

Assembly: System.Security.Cryptography

Inheritance: object → MarshalByRefObjectIO.​Stream → CryptoStream

Implemented Interfaces

Defines a stream that links data streams to cryptographic transformations.

Properties

public bool
CanRead
Gets a value indicating whether the current <see cref="T:System.Security.Cryptography.CryptoStream" /> is readable.
public bool
CanSeek
Gets a value indicating whether you can seek within the current <see cref="T:System.Security.Cryptography.CryptoStream" /> .
public bool
CanWrite
Gets a value indicating whether the current <see cref="T:System.Security.Cryptography.CryptoStream" /> is writable.
public bool
HasFlushedFinalBlock
Gets a value indicating whether the final buffer block has been written to the underlying stream.
public long
Length
Gets the length in bytes of the stream.
public long
Position
Gets or sets the position within the current stream.
public bool
CanTimeout
public int
ReadTimeout
public int
WriteTimeout

Methods

public IAsyncResult
BeginRead​(byte[] buffer, int offset, int count, AsyncCallback? callback, object state)
Begins an asynchronous read operation. (Consider using <see cref="Overload:System.Security.Cryptography.CryptoStream.ReadAsync" /> instead.)
Returns An <see cref="T:System.IAsyncResult" /> that represents the asynchronous read, which could still be pending.
buffer The buffer to read the data into.
offset The byte offset in <paramref name="buffer" /> at which to begin writing data read from the stream.
count The maximum number of bytes to read.
callback An optional asynchronous callback, to be called when the read is complete.
state A user-provided object that distinguishes this particular asynchronous read request from other requests.
public IAsyncResult
BeginWrite​(byte[] buffer, int offset, int count, AsyncCallback? callback, object state)
Begins an asynchronous write operation. (Consider using <see cref="Overload:System.Security.Cryptography.CryptoStream.WriteAsync" /> instead.)
Returns An <see langword="IAsyncResult" /> that represents the asynchronous write, which could still be pending.
buffer The buffer to write data from.
offset The byte offset in <paramref name="buffer" /> from which to begin writing.
count The maximum number of bytes to write.
callback An optional asynchronous callback, to be called when the write is complete.
state A user-provided object that distinguishes this particular asynchronous write request from other requests.
public void
Clear​()
Releases all resources used by the <see cref="T:System.Security.Cryptography.CryptoStream" /> .
public void
CopyTo​(IO.​Stream destination, int bufferSize)
Reads the bytes from the underlying stream, applies the relevant cryptographic transforms, and writes the result to the destination stream.
destination The stream to which the contents of the current stream will be copied.
bufferSize The size, in bytes, of the buffer to use for reading from the underlying stream. This value must be greater than zero. The default size is 81920 bytes.
CopyToAsync​(IO.​Stream destination, int bufferSize, Threading.​CancellationToken cancellationToken)
Asynchronously reads the bytes from the underlying stream, applies the relevant cryptographic transforms, and writes the result to the destination stream.
Returns A task that represents the asynchronous copy operation.
destination The stream to which the contents of the current stream will be copied.
bufferSize The size, in bytes, of the buffer. This value must be greater than zero. The default size is 81920.
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
protected void
Dispose​(bool disposing)
Releases the unmanaged resources used by the <see cref="T:System.Security.Cryptography.CryptoStream" /> and optionally releases the managed resources.
disposing <see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
DisposeAsync​()
Asynchronously releases the unmanaged resources used by the <see cref="T:System.Security.Cryptography.CryptoStream" /> .
Returns A task that represents the asynchronous dispose operation.
public int
EndRead​(IAsyncResult asyncResult)
Waits for the pending asynchronous read to complete. (Consider using <see cref="Overload:System.Security.Cryptography.CryptoStream.ReadAsync" /> instead.)
Returns The number of bytes read from the stream, between zero (0) and the number of bytes you requested. Streams return zero (0) only at the end of the stream, otherwise, they should block until at least one byte is available.
asyncResult The reference to the pending asynchronous request to finish.
public void
EndWrite​(IAsyncResult asyncResult)
Ends an asynchronous write operation. (Consider using <see cref="Overload:System.Security.Cryptography.CryptoStream.WriteAsync" /> instead.)
asyncResult A reference to the outstanding asynchronous I/O request.
public void
Flush​()
Clears all buffers for the current stream and causes any buffered data to be written to the underlying device.
FlushAsync​(Threading.​CancellationToken cancellationToken)
Clears all buffers for the current stream asynchronously, causes any buffered data to be written to the underlying device, and monitors cancellation requests.
Returns A task that represents the asynchronous flush operation.
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public void
FlushFinalBlock​()
Updates the underlying data source or repository with the current state of the buffer, then clears the buffer.
FlushFinalBlockAsync​(Threading.​CancellationToken cancellationToken = null)
Asynchronously updates the underlying data source or repository with the current state of the buffer, then clears the buffer.
Returns A task that represents the asynchronous flush operation.
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public int
Read​(byte[] buffer, int offset, int count)
Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
Returns 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.
buffer An array of bytes. A maximum of <paramref name="count" /> bytes are read from the current stream and stored in <paramref name="buffer" /> .
offset The byte offset in <paramref name="buffer" /> at which to begin storing the data read from the current stream.
count The maximum number of bytes to be read from the current stream.
ReadAsync​(byte[] buffer, int offset, int count, Threading.​CancellationToken cancellationToken)
Reads a sequence of bytes from the current stream asynchronously, advances the position within the stream by the number of bytes read, and monitors cancellation requests.
Returns A task that represents the asynchronous read operation. The value of the task object's <paramref name="TResult" /> parameter contains the total number of bytes read into the buffer. The result can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if the end of the stream has been reached.
buffer The buffer to write the data into.
offset The byte offset in <paramref name="buffer" /> at which to begin writing data from the stream.
count The maximum number of bytes to read.
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
ReadAsync​(Memory<​byte> buffer, Threading.​CancellationToken cancellationToken = null)
Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.
Returns A task that represents the asynchronous read operation. The value of its <see cref="P:System.Threading.Tasks.ValueTask`1.Result" /> property contains the total number of bytes read into the buffer. The result value can be less than the number of bytes allocated in the buffer if that many bytes are not currently available, or it can be 0 (zero) if the end of the stream has been reached.
buffer The region of memory to write the data into.
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public int
ReadByte​()
Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
Returns The unsigned byte cast to an <see cref="T:System.Int32" /> , or -1 if at the end of the stream.
public long
Seek​(long offset, IO.​SeekOrigin origin)
Sets the position within the current stream.
Returns This method is not supported.
offset A byte offset relative to the <paramref name="origin" /> parameter.
origin A <see cref="T:System.IO.SeekOrigin" /> object indicating the reference point used to obtain the new position.
public void
SetLength​(long value)
Sets the length of the current stream.
value The desired length of the current stream in bytes.
public void
Write​(byte[] buffer, int offset, int count)
Writes a sequence of bytes to the current <see cref="T:System.Security.Cryptography.CryptoStream" /> and advances the current position within the stream by the number of bytes written.
buffer An array of bytes. This method copies <paramref name="count" /> bytes from <paramref name="buffer" /> to the current stream.
offset The byte offset in <paramref name="buffer" /> at which to begin copying bytes to the current stream.
count The number of bytes to be written to the current stream.
WriteAsync​(byte[] buffer, int offset, int count, Threading.​CancellationToken cancellationToken)
Writes a sequence of bytes to the current stream asynchronously, advances the current position within the stream by the number of bytes written, and monitors cancellation requests.
Returns A task that represents the asynchronous write operation.
buffer The buffer to write data from.
offset The zero-based byte offset in <paramref name="buffer" /> from which to begin writing bytes to the stream.
count The maximum number of bytes to write.
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
WriteAsync​(ReadOnlyMemory<​byte> buffer, Threading.​CancellationToken cancellationToken = null)
Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.
Returns A task that represents the asynchronous write operation.
buffer The region of memory to write data from.
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public void
WriteByte​(byte value)
Writes a byte to the current position in the stream and advances the position within the stream by one byte.
value The byte to write to the stream.
public void
Close​()
Inherited from IO.​Stream
public void
CopyTo​(IO.​Stream destination)
Inherited from IO.​Stream
CopyToAsync​(IO.​Stream destination)
Inherited from IO.​Stream
CopyToAsync​(IO.​Stream destination, int bufferSize)
Inherited from IO.​Stream
CopyToAsync​(IO.​Stream destination, Threading.​CancellationToken cancellationToken)
Inherited from IO.​Stream
CreateWaitHandle​()
Inherited from IO.​Stream
public void
Dispose​()
Inherited from IO.​Stream
FlushAsync​()
Inherited from IO.​Stream
protected void
ObjectInvariant​()
Inherited from IO.​Stream
public int
Read​(Span<​byte> buffer)
Inherited from IO.​Stream
ReadAsync​(byte[] buffer, int offset, int count)
Inherited from IO.​Stream
public int
ReadAtLeast​(Span<​byte> buffer, int minimumBytes, bool throwOnEndOfStream = true)
Inherited from IO.​Stream
ReadAtLeastAsync​(Memory<​byte> buffer, int minimumBytes, bool throwOnEndOfStream = true, Threading.​CancellationToken cancellationToken = null)
Inherited from IO.​Stream
public void
ReadExactly​(byte[] buffer, int offset, int count)
Inherited from IO.​Stream
public void
ReadExactly​(Span<​byte> buffer)
Inherited from IO.​Stream
ReadExactlyAsync​(byte[] buffer, int offset, int count, Threading.​CancellationToken cancellationToken = null)
Inherited from IO.​Stream
ReadExactlyAsync​(Memory<​byte> buffer, Threading.​CancellationToken cancellationToken = null)
Inherited from IO.​Stream
public void
Write​(ReadOnlySpan<​byte> buffer)
Inherited from IO.​Stream
WriteAsync​(byte[] buffer, int offset, int count)
Inherited from IO.​Stream
public object
GetLifetimeService​()
Inherited from MarshalByRefObject
public object
InitializeLifetimeService​()
Inherited from MarshalByRefObject
protected MarshalByRefObject
MemberwiseClone​(bool cloneIdentity)
Inherited from MarshalByRefObject
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object