The EnableSecurity method enables a secure communications
session with the remote host, automatically negotiating the
encryption algorithm and validating the certificate. If the socket
was created using the Connect method to establish a client
connection, then EnableSecurity will initiate the handshake
with the remote host to establish a secure session. If the
Accept method was used to accept a connection from a client,
then the method will block and wait for the remote host to initiate
the handshake.
This method is useful if the application needs to establish an
initial, non-secure connection to the remote host and then negotiate
a secure connection at a later point. If the method succeeds, all
subsequent calls to Read and Write to receive and send
data will be encrypted.
If no arguments are specified, then the security credentials
established with a previous call to CreateSecurityCredentials
will be used. If a certificate name is specified, then the current
security credentials will be updated to use that certificate.