Security
Ssl

SSL

The SSL class provides methods for establishing and authenticating secure socket layer (SSL) connections between a server and a client.

Methods

AcceptAndAuthenticateClientAsync

  • Purpose: Asynchronously accepts a client connection on a listening TCP port and authenticates the client using SSL.
  • Parameters:
    • TcpListener listener: The TCP listener waiting for client connections.
    • X509Certificate2 serverCertificate: The certificate used by the server to authenticate itself to the client.
  • Returns: Task<SslStream>: An SSL stream representing the secure connection to the client.
  • Usage Example:
var listener = new TcpListener(IPAddress.Any, 443);
var serverCertificate = new X509Certificate2("server.pfx", "password");
var sslStream = await SSL.AcceptAndAuthenticateClientAsync(listener, serverCertificate);

ConnectAndAuthenticateServerAsync

  • Purpose: Asynchronously establishes and authenticates an SSL connection to a server.
  • Parameters:
    • string serverHost: The hostname of the server to connect to.
    • int serverPort: The port number of the server.
  • Returns: Task<SslStream>: An SSL stream representing the secure connection to the server.
  • Usage Example:
var sslStream = await SSL.ConnectAndAuthenticateServerAsync("example.com", 443);