Class SslStreamEx
Inherited Members
Namespace: CryptoPro.Net.Security
Assembly: CryptoPro.Net.Security.dll
Syntax
public class SslStreamEx : SslStream, IAsyncDisposable, IDisposable
Constructors
SslStreamEx(Stream)
Declaration
public SslStreamEx(Stream innerStream)
Parameters
Type | Name | Description |
---|---|---|
Stream | innerStream |
SslStreamEx(Stream, bool)
Declaration
public SslStreamEx(Stream innerStream, bool leaveInnerStreamOpen)
Parameters
Type | Name | Description |
---|---|---|
Stream | innerStream | |
bool | leaveInnerStreamOpen |
SslStreamEx(Stream, bool, RemoteCertificateValidationCallback?)
Declaration
public SslStreamEx(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback? userCertificateValidationCallback)
Parameters
Type | Name | Description |
---|---|---|
Stream | innerStream | |
bool | leaveInnerStreamOpen | |
RemoteCertificateValidationCallback | userCertificateValidationCallback |
SslStreamEx(Stream, bool, RemoteCertificateValidationCallback?, LocalCertificateSelectionCallback?)
Declaration
public SslStreamEx(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback? userCertificateValidationCallback, LocalCertificateSelectionCallback? userCertificateSelectionCallback)
Parameters
Type | Name | Description |
---|---|---|
Stream | innerStream | |
bool | leaveInnerStreamOpen | |
RemoteCertificateValidationCallback | userCertificateValidationCallback | |
LocalCertificateSelectionCallback | userCertificateSelectionCallback |
SslStreamEx(Stream, bool, RemoteCertificateValidationCallback?, LocalCertificateSelectionCallback?, EncryptionPolicy)
Declaration
public SslStreamEx(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback? userCertificateValidationCallback, LocalCertificateSelectionCallback? userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy)
Parameters
Type | Name | Description |
---|---|---|
Stream | innerStream | |
bool | leaveInnerStreamOpen | |
RemoteCertificateValidationCallback | userCertificateValidationCallback | |
LocalCertificateSelectionCallback | userCertificateSelectionCallback | |
EncryptionPolicy | encryptionPolicy |
Properties
CanRead
Gets a bool value that indicates whether the underlying stream is readable.
Declaration
public override bool CanRead { get; }
Property Value
Type | Description |
---|---|
bool | true if authentication has occurred and the underlying stream is readable; otherwise false. |
Overrides
CanSeek
Gets a bool value that indicates whether the underlying stream is seekable.
Declaration
public override bool CanSeek { get; }
Property Value
Type | Description |
---|---|
bool | This property always returns false. |
Overrides
CanTimeout
Gets a bool value that indicates whether the underlying stream supports time-outs.
Declaration
public override bool CanTimeout { get; }
Property Value
Type | Description |
---|---|
bool | true if the underlying stream supports time-outs; otherwise, false. |
Overrides
CanWrite
Gets a bool value that indicates whether the underlying stream is writable.
Declaration
public override bool CanWrite { get; }
Property Value
Type | Description |
---|---|
bool | true if authentication has occurred and the underlying stream is writable; otherwise false. |
Overrides
CheckCertRevocationStatus
Gets a bool value that indicates whether the certificate revocation list is checked during the certificate validation process.
Declaration
public override bool CheckCertRevocationStatus { get; }
Property Value
Type | Description |
---|---|
bool | true if the certificate revocation list is checked; otherwise, false. |
Overrides
CipherAlgorithm
Gets a value that identifies the bulk encryption algorithm used by this SslStream.
Declaration
public override CipherAlgorithmType CipherAlgorithm { get; }
Property Value
Type | Description |
---|---|
CipherAlgorithmType | A value that identifies the bulk encryption algorithm used by this SslStream. |
Overrides
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The CipherAlgorithm property was accessed before the completion of the authentication process or the authentication process failed. |
CipherStrength
Gets a value that identifies the strength of the cipher algorithm used by this SslStream.
Declaration
public override int CipherStrength { get; }
Property Value
Type | Description |
---|---|
int | An int value that specifies the strength of the algorithm, in bits. |
Overrides
HashAlgorithm
Gets the algorithm used for generating message authentication codes (MACs).
Declaration
public override HashAlgorithmType HashAlgorithm { get; }
Property Value
Type | Description |
---|---|
HashAlgorithmType | The algorithm used for generating message authentication codes (MACs). |
Overrides
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The HashAlgorithm property was accessed before the completion of the authentication process or the authentication process failed. |
HashStrength
Gets a value that identifies the strength of the hash algorithm used by this instance.
Declaration
public override int HashStrength { get; }
Property Value
Type | Description |
---|---|
int | An int value that specifies the strength of the HashAlgorithmType algorithm, in bits. Valid values are 128 or 160. |
Overrides
IsAuthenticated
Gets a bool value that indicates whether authentication was successful.
Declaration
public override bool IsAuthenticated { get; }
Property Value
Type | Description |
---|---|
bool | true if successful authentication occurred; otherwise, false. |
Overrides
IsEncrypted
Declaration
public override bool IsEncrypted { get; }
Property Value
Type | Description |
---|---|
bool | true if data is encrypted before being transmitted over the network and decrypted when it reaches the remote endpoint; otherwise false. |
Overrides
IsMutuallyAuthenticated
Gets a bool value that indicates whether both server and client have been authenticated.
Declaration
public override bool IsMutuallyAuthenticated { get; }
Property Value
Type | Description |
---|---|
bool | true if both server and client have been authenticated; otherwise false. |
Overrides
IsServer
Gets a bool value that indicates whether the local side of the connection used by this SslStream was authenticated as the server.
Declaration
public override bool IsServer { get; }
Property Value
Type | Description |
---|---|
bool | true if the local endpoint was successfully authenticated as the server side of the authenticated connection; otherwise false. |
Overrides
IsSigned
Gets a bool value that indicates whether the data sent using this stream is signed.
Declaration
public override bool IsSigned { get; }
Property Value
Type | Description |
---|---|
bool | true if the data is signed before being transmitted; otherwise false. |
Overrides
KeyExchangeAlgorithm
Gets the key exchange algorithm used by this SslStream.
Declaration
public override ExchangeAlgorithmType KeyExchangeAlgorithm { get; }
Property Value
Type | Description |
---|---|
ExchangeAlgorithmType | An ExchangeAlgorithmType value. |
Overrides
KeyExchangeStrength
Gets a value that identifies the strength of the key exchange algorithm used by this instance.
Declaration
public override int KeyExchangeStrength { get; }
Property Value
Type | Description |
---|---|
int | An int value that specifies the strength of the ExchangeAlgorithmType algorithm, in bits. |
Overrides
Length
Gets the length of the underlying stream.
Declaration
public override long Length { get; }
Property Value
Type | Description |
---|---|
long | The length of the underlying stream. |
Overrides
Exceptions
Type | Condition |
---|---|
NotSupportedException | Getting the value of this property is not supported when the underlying stream is a NetworkStream. |
LocalCertificate
Declaration
public CpX509Certificate? LocalCertificate { get; }
Property Value
Type | Description |
---|---|
CpX509Certificate |
NegotiatedApplicationProtocol
Declaration
public SslApplicationProtocol NegotiatedApplicationProtocol { get; }
Property Value
Type | Description |
---|---|
SslApplicationProtocol |
NegotiatedCipherSuite
Gets the cipher suite which was negotiated for this connection.
Declaration
[CLSCompliant(false)]
public override TlsCipherSuite NegotiatedCipherSuite { get; }
Property Value
Type | Description |
---|---|
TlsCipherSuite | One of the enumeration values that identifies the cipher suite which was negotiated for this connection. |
Overrides
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The property was accessed before the completion of the authentication process or the authentication process failed. |
Position
Gets or sets the current position in the underlying stream.
Declaration
public override long Position { get; set; }
Property Value
Type | Description |
---|---|
long | The current position in the underlying stream. |
Overrides
Exceptions
Type | Condition |
---|---|
NotSupportedException | Setting this property is not supported. -or- Getting the value of this property is not supported when the underlying stream is a NetworkStream. |
ReadTimeout
Gets or sets the amount of time, expressed in milliseconds, a read operation blocks waiting for data.
Declaration
public override int ReadTimeout { get; set; }
Property Value
Type | Description |
---|---|
int | The amount of time, in milliseconds, that elapses before a synchronous read operation fails. |
Overrides
RemoteCertificate
Declaration
public CpX509Certificate? RemoteCertificate { get; }
Property Value
Type | Description |
---|---|
CpX509Certificate |
SslProtocol
Gets a value that indicates the security protocol used to authenticate this connection.
Declaration
public override SslProtocols SslProtocol { get; }
Property Value
Type | Description |
---|---|
SslProtocols | The SslProtocols value that represents protocols used for authentication. |
Overrides
TransportContext
Declaration
public TransportContext TransportContext { get; }
Property Value
Type | Description |
---|---|
TransportContext |
WriteTimeout
Gets or sets the amount of time a write operation blocks waiting for data.
Declaration
public override int WriteTimeout { get; set; }
Property Value
Type | Description |
---|---|
int | The amount of time that elapses before a synchronous write operation fails. |
Overrides
Methods
AuthenticateAsClient(CpSslClientAuthenticationOptions)
Declaration
public void AuthenticateAsClient(CpSslClientAuthenticationOptions sslClientAuthenticationOptions)
Parameters
Type | Name | Description |
---|---|---|
CpSslClientAuthenticationOptions | sslClientAuthenticationOptions |
AuthenticateAsClient(string)
Called by clients to authenticate the server and optionally the client in a client-server connection.
Declaration
public override void AuthenticateAsClient(string targetHost)
Parameters
Type | Name | Description |
---|---|---|
string | targetHost | The name of the server that shares this SslStream. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Server authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
AuthenticateAsClient(string, X509CertificateCollection?, bool)
Called by clients to authenticate the server and optionally the client in a client-server connection. The authentication process uses the specified certificate collection, and the system default SSL protocol.
Declaration
public override void AuthenticateAsClient(string targetHost, X509CertificateCollection? clientCertificates, bool checkCertificateRevocation)
Parameters
Type | Name | Description |
---|---|---|
string | targetHost | The name of the server that will share this SslStream. |
X509CertificateCollection | clientCertificates | The X509CertificateCollection that contains client certificates. |
bool | checkCertificateRevocation | A bool value that specifies whether the certificate revocation list is checked during authentication. |
Overrides
AuthenticateAsClient(string, X509CertificateCollection?, SslProtocols, bool)
Called by clients to authenticate the server and optionally the client in a client-server connection. The authentication process uses the specified certificate collection and SSL protocol.
Declaration
public override void AuthenticateAsClient(string targetHost, X509CertificateCollection? clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
Parameters
Type | Name | Description |
---|---|---|
string | targetHost | The name of the server that will share this SslStream. |
X509CertificateCollection | clientCertificates | The X509CertificateCollection that contains client certificates. |
SslProtocols | enabledSslProtocols | The SslProtocols value that represents protocols used for authentication. |
bool | checkCertificateRevocation | A bool value that specifies whether the certificate revocation list is checked during authentication. |
Overrides
AuthenticateAsClientAsync(CpSslClientAuthenticationOptions, CancellationToken)
Declaration
public Task AuthenticateAsClientAsync(CpSslClientAuthenticationOptions sslClientAuthenticationOptions, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CpSslClientAuthenticationOptions | sslClientAuthenticationOptions | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
AuthenticateAsClientAsync(string)
Called by clients to authenticate the server and optionally the client in a client-server connection as an asynchronous operation.
Declaration
public override Task AuthenticateAsClientAsync(string targetHost)
Parameters
Type | Name | Description |
---|---|---|
string | targetHost | The name of the server that shares this SslStream. |
Returns
Type | Description |
---|---|
Task | The task object representing the asynchronous operation. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Server authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
AuthenticateAsClientAsync(string, X509CertificateCollection?, bool)
Called by clients to authenticate the server and optionally the client in a client-server connection as an asynchronous operation. The authentication process uses the specified certificate collection and the system default SSL protocol.
Declaration
public override Task AuthenticateAsClientAsync(string targetHost, X509CertificateCollection? clientCertificates, bool checkCertificateRevocation)
Parameters
Type | Name | Description |
---|---|---|
string | targetHost | The name of the server that will share this SslStream. |
X509CertificateCollection | clientCertificates | The X509CertificateCollection that contains client certificates. |
bool | checkCertificateRevocation | A bool value that specifies whether the certificate revocation list is checked during authentication. |
Returns
Type | Description |
---|---|
Task | The task object representing the asynchronous operation. |
Overrides
Exceptions
Type | Condition |
---|---|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Server authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
AuthenticateAsClientAsync(string, X509CertificateCollection?, SslProtocols, bool)
Called by clients to authenticate the server and optionally the client in a client-server connection as an asynchronous operation. The authentication process uses the specified certificate collection and SSL protocol.
Declaration
public override Task AuthenticateAsClientAsync(string targetHost, X509CertificateCollection? clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
Parameters
Type | Name | Description |
---|---|---|
string | targetHost | The name of the server that will share this SslStream. |
X509CertificateCollection | clientCertificates | The X509CertificateCollection that contains client certificates. |
SslProtocols | enabledSslProtocols | The SslProtocols value that represents protocols used for authentication. |
bool | checkCertificateRevocation | A bool value that specifies whether the certificate revocation list is checked during authentication. |
Returns
Type | Description |
---|---|
Task | The task object representing the asynchronous operation. |
Overrides
Exceptions
Type | Condition |
---|---|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Server authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
AuthenticateAsServer(X509Certificate)
Called by servers to authenticate the server and optionally the client in a client-server connection using the specified certificate.
Declaration
public override void AuthenticateAsServer(X509Certificate serverCertificate)
Parameters
Type | Name | Description |
---|---|---|
X509Certificate | serverCertificate | The certificate used to authenticate the server. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Client authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
PlatformNotSupportedException | The System.Net.Security.SslStream.AuthenticateAsServer* method is not supported on Windows 95, Windows 98, or Windows Millennium. |
AuthenticateAsServer(X509Certificate, bool, bool)
Called by servers to authenticate the server and optionally the client in a client-server connection using the specified certificates and requirements, and using the system default security protocol.
Declaration
public override void AuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, bool checkCertificateRevocation)
Parameters
Type | Name | Description |
---|---|---|
X509Certificate | serverCertificate | The X509Certificate used to authenticate the server. |
bool | clientCertificateRequired | A bool value that specifies whether the client is asked for a certificate for authentication. Note that this is only a request -- if no certificate is provided, the server still accepts the connection request. |
bool | checkCertificateRevocation | A bool value that specifies whether the certificate revocation list is checked during authentication. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Client authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
PlatformNotSupportedException | The System.Net.Security.SslStream.AuthenticateAsServer* method is not supported on Windows 95, Windows 98, or Windows Millennium. |
AuthenticateAsServer(X509Certificate, bool, SslProtocols, bool)
Called by servers to authenticate the server and optionally the client in a client-server connection using the specified certificates, requirements and security protocol.
Declaration
public override void AuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
Parameters
Type | Name | Description |
---|---|---|
X509Certificate | serverCertificate | The X509Certificate used to authenticate the server. |
bool | clientCertificateRequired | A bool value that specifies whether the client is asked for a certificate for authentication. Note that this is only a request -- if no certificate is provided, the server still accepts the connection request. |
SslProtocols | enabledSslProtocols | The SslProtocols value that represents protocols used for authentication. |
bool | checkCertificateRevocation | A bool value that specifies whether the certificate revocation list is checked during authentication. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Client authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
PlatformNotSupportedException | The System.Net.Security.SslStream.AuthenticateAsServer* method is not supported on Windows 95, Windows 98, or Windows Millennium. |
AuthenticateAsServerAsync(CpSslServerAuthenticationOptions, CancellationToken)
Declaration
public Task AuthenticateAsServerAsync(CpSslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CpSslServerAuthenticationOptions | sslServerAuthenticationOptions | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
AuthenticateAsServerAsync(X509Certificate)
Called by servers to authenticate the server and optionally the client in a client-server connection using the specified certificate as an asynchronous operation.
Declaration
public override Task AuthenticateAsServerAsync(X509Certificate serverCertificate)
Parameters
Type | Name | Description |
---|---|---|
X509Certificate | serverCertificate | The certificate used to authenticate the server. |
Returns
Type | Description |
---|---|
Task | The task object representing the asynchronous operation. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Client authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
PlatformNotSupportedException | The System.Net.Security.SslStream.AuthenticateAsServerAsync* method is not supported on Windows 95, Windows 98, or Windows Millennium. |
AuthenticateAsServerAsync(X509Certificate, bool, bool)
Called by servers to authenticate the server and optionally the client in a client-server connection using the specified certificates, requirements and security protocol as an asynchronous operation.
Declaration
public override Task AuthenticateAsServerAsync(X509Certificate serverCertificate, bool clientCertificateRequired, bool checkCertificateRevocation)
Parameters
Type | Name | Description |
---|---|---|
X509Certificate | serverCertificate | The X509Certificate used to authenticate the server. |
bool | clientCertificateRequired | A bool value that specifies whether the client is asked for a certificate for authentication. Note that this is only a request -- if no certificate is provided, the server still accepts the connection request. |
bool | checkCertificateRevocation | A bool value that specifies whether the certificate revocation list is checked during authentication. |
Returns
Type | Description |
---|---|
Task | The task object representing the asynchronous operation. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Client authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
AuthenticateAsServerAsync(X509Certificate, bool, SslProtocols, bool)
Called by servers to authenticate the server and optionally the client in a client-server connection using the specified certificates, requirements and security protocol as an asynchronous operation.
Declaration
public override Task AuthenticateAsServerAsync(X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
Parameters
Type | Name | Description |
---|---|---|
X509Certificate | serverCertificate | The X509Certificate used to authenticate the server. |
bool | clientCertificateRequired | A bool value that specifies whether the client is asked for a certificate for authentication. Note that this is only a request -- if no certificate is provided, the server still accepts the connection request. |
SslProtocols | enabledSslProtocols | The SslProtocols value that represents protocols used for authentication. |
bool | checkCertificateRevocation | A bool value that specifies whether the certificate revocation list is checked during authentication. |
Returns
Type | Description |
---|---|
Task | The task object representing the asynchronous operation. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Client authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
BeginAuthenticateAsClient(string, AsyncCallback?, object?)
Called by clients to begin an asynchronous operation to authenticate the server and optionally the client.
Declaration
public override IAsyncResult BeginAuthenticateAsClient(string targetHost, AsyncCallback? asyncCallback, object? asyncState)
Parameters
Type | Name | Description |
---|---|---|
string | targetHost | The name of the server that shares this SslStream. |
AsyncCallback | asyncCallback | An AsyncCallback delegate that references the method to invoke when the authentication is complete. |
object | asyncState | A user-defined object that contains information about the operation. This object is passed to the |
Returns
Type | Description |
---|---|
IAsyncResult | An IAsyncResult object that indicates the status of the asynchronous operation. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Server authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
BeginAuthenticateAsClient(string, X509CertificateCollection?, bool, AsyncCallback?, object?)
Called by clients to begin an asynchronous operation to authenticate the server and optionally the client using the specified certificates and the system default security protocol.
Declaration
public override IAsyncResult BeginAuthenticateAsClient(string targetHost, X509CertificateCollection? clientCertificates, bool checkCertificateRevocation, AsyncCallback? asyncCallback, object? asyncState)
Parameters
Type | Name | Description |
---|---|---|
string | targetHost | The name of the server that shares this SslStream. |
X509CertificateCollection | clientCertificates | The X509CertificateCollection containing client certificates. |
bool | checkCertificateRevocation | A bool value that specifies whether the certificate revocation list is checked during authentication. |
AsyncCallback | asyncCallback | An AsyncCallback delegate that references the method to invoke when the authentication is complete. |
object | asyncState | A user-defined object that contains information about the operation. This object is passed to the |
Returns
Type | Description |
---|---|
IAsyncResult | An IAsyncResult object that indicates the status of the asynchronous operation. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Server authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
BeginAuthenticateAsClient(string, X509CertificateCollection?, SslProtocols, bool, AsyncCallback?, object?)
Called by clients to begin an asynchronous operation to authenticate the server and optionally the client using the specified certificates and security protocol.
Declaration
public override IAsyncResult BeginAuthenticateAsClient(string targetHost, X509CertificateCollection? clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback? asyncCallback, object? asyncState)
Parameters
Type | Name | Description |
---|---|---|
string | targetHost | The name of the server that shares this SslStream. |
X509CertificateCollection | clientCertificates | The X509CertificateCollection containing client certificates. |
SslProtocols | enabledSslProtocols | The SslProtocols value that represents protocols used for authentication. |
bool | checkCertificateRevocation | A bool value that specifies whether the certificate revocation list is checked during authentication. |
AsyncCallback | asyncCallback | An AsyncCallback delegate that references the method to invoke when the authentication is complete. |
object | asyncState | A user-defined object that contains information about the operation. This object is passed to the |
Returns
Type | Description |
---|---|
IAsyncResult | An IAsyncResult object that indicates the status of the asynchronous operation. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Server authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
BeginAuthenticateAsServer(X509Certificate, AsyncCallback?, object?)
Called by servers to begin an asynchronous operation to authenticate the client and optionally the server in a client-server connection.
Declaration
public override IAsyncResult BeginAuthenticateAsServer(X509Certificate serverCertificate, AsyncCallback? asyncCallback, object? asyncState)
Parameters
Type | Name | Description |
---|---|---|
X509Certificate | serverCertificate | The X509Certificate used to authenticate the server. |
AsyncCallback | asyncCallback | An AsyncCallback delegate that references the method to invoke when the authentication is complete. |
object | asyncState | A user-defined object that contains information about the operation. This object is passed to the |
Returns
Type | Description |
---|---|
IAsyncResult | An IAsyncResult object indicating the status of the asynchronous operation. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Client authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
PlatformNotSupportedException | The System.Net.Security.SslStream.BeginAuthenticateAsServer* method is not supported on Windows 95, Windows 98, or Windows Millennium. |
BeginAuthenticateAsServer(X509Certificate, bool, bool, AsyncCallback?, object?)
Called by servers to begin an asynchronous operation to authenticate the server and optionally the client using the specified certificates and requirements, and the system default security protocol.
Declaration
public override IAsyncResult BeginAuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, bool checkCertificateRevocation, AsyncCallback? asyncCallback, object? asyncState)
Parameters
Type | Name | Description |
---|---|---|
X509Certificate | serverCertificate | The X509Certificate used to authenticate the server. |
bool | clientCertificateRequired | A bool value that specifies whether the client is asked for a certificate for authentication. Note that this is only a request -- if no certificate is provided, the server still accepts the connection request. |
bool | checkCertificateRevocation | A bool value that specifies whether the certificate revocation list is checked during authentication. |
AsyncCallback | asyncCallback | An AsyncCallback delegate that references the method to invoke when the authentication is complete. |
object | asyncState | A user-defined object that contains information about the operation. This object is passed to the |
Returns
Type | Description |
---|---|
IAsyncResult | An IAsyncResult object that indicates the status of the asynchronous operation. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Server authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
PlatformNotSupportedException | The System.Net.Security.SslStream.BeginAuthenticateAsServer* method is not supported on Windows 95, Windows 98, or Windows Millennium. |
BeginAuthenticateAsServer(X509Certificate, bool, SslProtocols, bool, AsyncCallback?, object?)
Called by servers to begin an asynchronous operation to authenticate the server and optionally the client using the specified certificates, requirements and security protocol.
Declaration
public override IAsyncResult BeginAuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback? asyncCallback, object? asyncState)
Parameters
Type | Name | Description |
---|---|---|
X509Certificate | serverCertificate | The X509Certificate used to authenticate the server. |
bool | clientCertificateRequired | A bool value that specifies whether the client is asked for a certificate for authentication. Note that this is only a request -- if no certificate is provided, the server still accepts the connection request. |
SslProtocols | enabledSslProtocols | The SslProtocols value that represents protocols used for authentication. |
bool | checkCertificateRevocation | A bool value that specifies whether the certificate revocation list is checked during authentication. |
AsyncCallback | asyncCallback | An AsyncCallback delegate that references the method to invoke when the authentication is complete. |
object | asyncState | A user-defined object that contains information about the operation. This object is passed to the |
Returns
Type | Description |
---|---|
IAsyncResult | An IAsyncResult object that indicates the status of the asynchronous operation. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | Authentication has already occurred. -or- Server authentication using this SslStream was tried previously. -or- Authentication is already in progress. |
ObjectDisposedException | This object has been closed. |
PlatformNotSupportedException | The System.Net.Security.SslStream.BeginAuthenticateAsServer* method is not supported on Windows 95, Windows 98, or Windows Millennium. |
BeginRead(byte[], int, int, AsyncCallback?, object?)
Begins an asynchronous read operation that reads data from the stream and stores it in the specified array.
Declaration
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | A byte array that receives the bytes read from the stream. |
int | offset | The zero-based location in |
int | count | The maximum number of bytes to read from the stream. |
AsyncCallback | asyncCallback | An AsyncCallback delegate that references the method to invoke when the read operation is complete. |
object | asyncState | A user-defined object that contains information about the read operation. This object is passed to the |
Returns
Type | Description |
---|---|
IAsyncResult | An IAsyncResult object that indicates the status of the asynchronous operation. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
-or-
-or-
|
IOException | The read operation failed. -or- Encryption is in use, but the data could not be decrypted. |
NotSupportedException | There is already a read operation in progress. |
ObjectDisposedException | This object has been closed. |
InvalidOperationException | Authentication has not occurred. |
BeginWrite(byte[], int, int, AsyncCallback?, object?)
Begins an asynchronous write operation that writes bytes from the specified buffer to the stream.
Declaration
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | A byte array that supplies the bytes to be written to the stream. |
int | offset | The zero-based location in |
int | count | An int value that specifies the number of bytes to read from |
AsyncCallback | asyncCallback | An AsyncCallback delegate that references the method to invoke when the write operation is complete. |
object | asyncState | A user-defined object that contains information about the write operation. This object is passed to the |
Returns
Type | Description |
---|---|
IAsyncResult | An IAsyncResult object indicating the status of the asynchronous operation. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
-or-
-or-
|
IOException | The write operation failed. |
NotSupportedException | There is already a write operation in progress. |
ObjectDisposedException | This object has been closed. |
InvalidOperationException | Authentication has not occurred. |
Dispose(bool)
Releases the unmanaged resources used by the SslStream and optionally releases the managed resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | true to release both managed and unmanaged resources; false to release only unmanaged resources. |
Overrides
DisposeAsync()
Asynchronously releases the unmanaged and managed resources used by the SslStream.
Declaration
public override ValueTask DisposeAsync()
Returns
Type | Description |
---|---|
ValueTask | A task that represents the asynchronous dispose operation. |
Overrides
EndAuthenticateAsClient(IAsyncResult)
Ends a pending asynchronous server authentication operation started with a previous call to System.Net.Security.SslStream.BeginAuthenticateAsClient*.
Declaration
public override void EndAuthenticateAsClient(IAsyncResult asyncResult)
Parameters
Type | Name | Description |
---|---|---|
IAsyncResult | asyncResult | An IAsyncResult instance returned by a call to System.Net.Security.SslStream.BeginAuthenticateAsClient*. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | There is no pending server authentication to complete. |
EndAuthenticateAsServer(IAsyncResult)
Ends a pending asynchronous client authentication operation started with a previous call to System.Net.Security.SslStream.BeginAuthenticateAsClient*.
Declaration
public override void EndAuthenticateAsServer(IAsyncResult asyncResult)
Parameters
Type | Name | Description |
---|---|---|
IAsyncResult | asyncResult | An IAsyncResult instance returned by a call to System.Net.Security.SslStream.BeginAuthenticateAsClient*. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
AuthenticationException | The authentication failed and left this object in an unusable state. |
InvalidOperationException | There is no pending client authentication to complete. |
EndRead(IAsyncResult)
Ends an asynchronous read operation started with a previous call to BeginRead(byte[], int, int, AsyncCallback, object).
Declaration
public override int EndRead(IAsyncResult asyncResult)
Parameters
Type | Name | Description |
---|---|---|
IAsyncResult | asyncResult | An IAsyncResult instance returned by a call to BeginRead(byte[], int, int, AsyncCallback, object). |
Returns
Type | Description |
---|---|
int | A int value that specifies the number of bytes read from the underlying stream. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
InvalidOperationException | There is no pending read operation to complete. -or- Authentication has not occurred. |
IOException | The read operation failed. |
EndWrite(IAsyncResult)
Ends an asynchronous write operation started with a previous call to BeginWrite(byte[], int, int, AsyncCallback, object).
Declaration
public override void EndWrite(IAsyncResult asyncResult)
Parameters
Type | Name | Description |
---|---|---|
IAsyncResult | asyncResult | An IAsyncResult instance returned by a call to BeginWrite(byte[], int, int, AsyncCallback, object). |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
InvalidOperationException | There is no pending write operation to complete. -or- Authentication has not occurred. |
IOException | The write operation failed. |
~SslStreamEx()
Declaration
protected ~SslStreamEx()
Flush()
Causes any buffered data to be written to the underlying device.
Declaration
public override void Flush()
Overrides
FlushAsync(CancellationToken)
Asynchronously writes any buffered data to the underlying device.
Declaration
public override Task FlushAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
Task | A task that represents the asynchronous flush operation. |
Overrides
Read(byte[], int, int)
Reads data from this stream and stores it in the specified array.
Declaration
public override int Read(byte[] buffer, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | A byte array that receives the bytes read from this stream. |
int | offset | A int that contains the zero-based location in |
int | count | A int that contains the maximum number of bytes to read from this stream. |
Returns
Type | Description |
---|---|
int | A int value that specifies the number of bytes read. When there is no more data to be read, returns 0. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
-or-
-or-
|
IOException | The read operation failed. Check the inner exception, if present to determine the cause of the failure. |
NotSupportedException | There is already a read operation in progress. |
ObjectDisposedException | This object has been closed. |
InvalidOperationException | Authentication has not occurred. |
ReadAsync(byte[], int, int, CancellationToken)
Asynchronously reads data from this stream and stores it in the specified range of a byte array.
Declaration
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | The buffer that receives the bytes read from this stream. |
int | offset | The zero-based location in |
int | count | The maximum number of bytes to read from this stream. |
CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
Task<int> | A task that represents the asynchronous read operation. The value of its Result property contains the total number of bytes read into |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
-or-
-or-
|
InvalidOperationException | Authentication has not occurred. |
IOException | The read operation failed. Check the inner exception, if it is present, to determine the cause of the failure. |
NotSupportedException | There is already a read operation in progress. |
ObjectDisposedException | This object has been closed. |
ReadAsync(Memory<byte>, CancellationToken)
Asynchronously reads data from this stream and stores it in the specified memory range.
Declaration
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
Memory<byte> | buffer | The buffer that receives the bytes read from this stream. |
CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
ValueTask<int> | A task that represents the asynchronous read operation. The value of its Result property contains the total number of bytes read into |
Overrides
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Authentication has not occurred. |
IOException | The read operation failed. Check the inner exception, if it is present, to determine the cause of the failure. |
NotSupportedException | There is already a read operation in progress. |
ObjectDisposedException | This object has been closed. |
ReadByte()
Reads a byte from the SslStream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
Declaration
public override int ReadByte()
Returns
Type | Description |
---|---|
int | The unsigned byte cast to an int, or -1 if at the end of the stream. |
Overrides
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Authentication has not occurred. |
IOException | The read operation failed. Check the inner exception, if present to determine the cause of the failure. |
NotSupportedException | There is already a read operation in progress. |
ObjectDisposedException | This object has been closed. |
Seek(long, SeekOrigin)
Throws a NotSupportedException.
Declaration
public override long Seek(long offset, SeekOrigin origin)
Parameters
Type | Name | Description |
---|---|---|
long | offset | This value is ignored. |
SeekOrigin | origin | This value is ignored. |
Returns
Type | Description |
---|---|
long | Always throws a NotSupportedException. |
Overrides
Exceptions
Type | Condition |
---|---|
NotSupportedException | Seeking is not supported by SslStream objects. |
SetLength(long)
Sets the length of the underlying stream.
Declaration
public override void SetLength(long value)
Parameters
Type | Name | Description |
---|---|---|
long | value | An long value that specifies the length of the stream. |
Overrides
ShutdownAsync()
Shuts down this SslStream.
Declaration
public override Task ShutdownAsync()
Returns
Type | Description |
---|---|
Task | The task object representing the asynchronous operation. |
Overrides
Write(byte[])
Declaration
public void Write(byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer |
Write(byte[], int, int)
Write the specified number of bytes to the underlying stream using the specified buffer and offset.
Declaration
public override void Write(byte[] buffer, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | A byte array that supplies the bytes written to the stream. |
int | offset | A int that contains the zero-based location in |
int | count | A int that contains the number of bytes to read from |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
-or-
-or-
|
IOException | The write operation failed. |
NotSupportedException | There is already a write operation in progress. |
ObjectDisposedException | This object has been closed. |
InvalidOperationException | Authentication has not occurred. |
WriteAsync(byte[], int, int, CancellationToken)
Asynchronously writes data to the underlying stream from the specified range of a byte array.
Declaration
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | The data to write to the underlying stream. |
int | offset | The location in |
int | count | The number of bytes to write to the underlying stream. |
CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
Task | A task that represents the asynchronous write operation. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
-or-
-or-
|
InvalidOperationException | Authentication has not occurred. |
IOException | The write operation failed. |
NotSupportedException | There is already a write operation in progress. |
ObjectDisposedException | This object has been closed. |
WriteAsync(ReadOnlyMemory<byte>, CancellationToken)
Asynchronously writes data to the underlying stream from a read-only byte memory range.
Declaration
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlyMemory<byte> | buffer | The data to write to the underlying stream. |
CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
ValueTask | A task that represents the asynchronous write operation. |
Overrides
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Authentication has not occurred. |
IOException | The write operation failed. |
NotSupportedException | There is already a write operation in progress. |
ObjectDisposedException | This object has been closed. |