CSocketWrench::EnableSecurity Method  
 
BOOL EnableSecurity();
BOOL EnableSecurity(
  LPCTSTR lpszCertName  
);
BOOL EnableSecurity(
  LPCTSTR lpszCertStore,  
  LPCTSTR lpszCertName  
);

The EnableSecurity method enables a secure session with the remote host.

Parameters

lpszCertStore
A pointer to a string which specifies the name of certificate store.
lpszCertName
A pointer to a string which specifies the common name for the certificate that will be used.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

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.

Requirements

Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header: Include cswsock10.h
Import Library: cswskv10.lib

See Also

CreateSecurityCredentials, DeleteSecurityCredentials, DisableSecurity