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

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)
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.
Returns An <see cref="T:System.IAsyncResult" /> that represents the asynchronous read, which could still be pending.
Begins an asynchronous read operation. (Consider using <see cref="Overload:System.Security.Cryptography.CryptoStream.ReadAsync" /> instead.)
public IAsyncResult
BeginWrite​(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
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.
Returns An <see langword="IAsyncResult" /> that represents the asynchronous write, which could still be pending.
Begins an asynchronous write operation. (Consider using <see cref="Overload:System.Security.Cryptography.CryptoStream.WriteAsync" /> instead.)
public void
Clear​()
Releases all resources used by the <see cref="T:System.Security.Cryptography.CryptoStream" /> .
public void
CopyTo​(IO.Stream destination, int bufferSize)
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.
Reads the bytes from the underlying stream, applies the relevant cryptographic transforms, and writes the result to the destination stream.
CopyToAsync​(IO.Stream destination, int bufferSize, Threading.CancellationToken cancellationToken)
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" /> .
Returns A task that represents the asynchronous copy operation.
Asynchronously reads the bytes from the underlying stream, applies the relevant cryptographic transforms, and writes the result to the destination stream.
protected void
Dispose​(bool disposing)
disposing <see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
Releases the unmanaged resources used by the <see cref="T:System.Security.Cryptography.CryptoStream" /> and optionally releases the managed resources.
DisposeAsync​()
Returns A task that represents the asynchronous dispose operation.
Asynchronously releases the unmanaged resources used by the <see cref="T:System.Security.Cryptography.CryptoStream" /> .
public int
EndRead​(IAsyncResult asyncResult)
asyncResult The reference to the pending asynchronous request to finish.
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.
Waits for the pending asynchronous read to complete. (Consider using <see cref="Overload:System.Security.Cryptography.CryptoStream.ReadAsync" /> instead.)
public void
EndWrite​(IAsyncResult asyncResult)
asyncResult A reference to the outstanding asynchronous I/O request.
Ends an asynchronous write operation. (Consider using <see cref="Overload:System.Security.Cryptography.CryptoStream.WriteAsync" /> instead.)
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)
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
Returns A task that represents the asynchronous flush operation.
Clears all buffers for the current stream asynchronously, causes any buffered data to be written to the underlying device, and monitors cancellation requests.
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)
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
Returns A task that represents the asynchronous flush operation.
Asynchronously updates the underlying data source or repository with the current state of the buffer, then clears the buffer.
public int
Read​(byte[] buffer, int offset, int count)
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.
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.
Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
ReadAsync​(byte[] buffer, int offset, int count, Threading.CancellationToken cancellationToken)
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" /> .
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.
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.
ReadAsync​(Memory`1 buffer, Threading.CancellationToken cancellationToken = null)
public int
ReadByte​()
Returns The unsigned byte cast to an <see cref="T:System.Int32" /> , or -1 if at the end of the stream.
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.
public long
Seek​(long offset, IO.SeekOrigin origin)
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.
Returns This method is not supported.
Sets the position within the current stream.
public void
SetLength​(long value)
value The desired length of the current stream in bytes.
Sets the length of the current stream.
public void
Write​(byte[] buffer, int offset, int count)
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.
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.
WriteAsync​(byte[] buffer, int offset, int count, Threading.CancellationToken cancellationToken)
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" /> .
Returns A task that represents the asynchronous write operation.
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.
WriteAsync​(ReadOnlyMemory`1 buffer, Threading.CancellationToken cancellationToken = null)
public void
WriteByte​(byte value)
value The byte to write to the stream.
Writes a byte to the current position in the stream and advances the position within the stream by one byte.
public void
Close​()
Inherited from Stream
public void
CopyTo​(IO.Stream destination)
Inherited from Stream
CopyToAsync​(IO.Stream destination)
Inherited from Stream
CopyToAsync​(IO.Stream destination, int bufferSize)
Inherited from Stream
CopyToAsync​(IO.Stream destination, Threading.CancellationToken cancellationToken)
Inherited from Stream
CreateWaitHandle​()
Inherited from Stream
public void
Dispose​()
Inherited from Stream
FlushAsync​()
Inherited from Stream
protected void
ObjectInvariant​()
Inherited from Stream
public int
Read​(Span`1 buffer)
Inherited from Stream
ReadAsync​(byte[] buffer, int offset, int count)
Inherited from Stream
public int
ReadAtLeast​(Span`1 buffer, int minimumBytes, bool throwOnEndOfStream = True)
Inherited from Stream
ReadAtLeastAsync​(Memory`1 buffer, int minimumBytes, bool throwOnEndOfStream = True, Threading.CancellationToken cancellationToken = null)
Inherited from Stream
public void
ReadExactly​(byte[] buffer, int offset, int count)
Inherited from Stream
public void
ReadExactly​(Span`1 buffer)
Inherited from Stream
ReadExactlyAsync​(byte[] buffer, int offset, int count, Threading.CancellationToken cancellationToken = null)
Inherited from Stream
ReadExactlyAsync​(Memory`1 buffer, Threading.CancellationToken cancellationToken = null)
Inherited from Stream
public void
Write​(ReadOnlySpan`1 buffer)
Inherited from Stream
WriteAsync​(byte[] buffer, int offset, int count)
Inherited from 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