Search code examples
c#sslstream

Difference between AuthenticateAsClient and AuthenticateAsServer


What is the difference between SslStream.AuthenticateAsClient and SslStream.AuthenticateAsServer methods?
When should I use what?
I checked many examples. But I can't understand what should be used by client and what should be used by server.


Solution

  • AuthenticateAsServer is called from the server process. Both overloads to this method (and its Async sibling) take an X509Certificate object, which is the server authentication certificate.

    AuthenticateAsClient is called from the client process. Both overloads to this method (and its Async sibling) take a string, which is the hostname to use for policy matching on the server's authentication certificate.