Sample code for 30+ languages & platforms
Visual Basic 6.0

Get the Server Certificate from a TLS Connection

See more Socket/SSL/TLS Examples

Demonstrates Socket.GetServerCert, which copies the certificate presented by the remote TLS server into a Cert object for inspection.

Background. The method returns false when the socket is not connected, is not using TLS, or no server certificate is available. Inspecting the certificate lets an application validate the server's identity.

Chilkat Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

Dim socket As New ChilkatSocket

'  Connect to the server using TLS.
Dim bTls As Long
bTls = 1
Dim maxWaitMs As Long
maxWaitMs = 5000
success = socket.Connect("example.com",5000,bTls,maxWaitMs)
If (success = 0) Then
    Debug.Print socket.LastErrorText
    Exit Sub
End If

'  Copy the certificate presented by the remote TLS server, then inspect it.  This can be used to
'  validate the server's identity.
Dim cert As New ChilkatCert
success = socket.GetServerCert(cert)
If (success = 0) Then
    Debug.Print socket.LastErrorText
    Exit Sub
End If

Debug.Print "Server certificate subject: " & cert.SubjectCN
Debug.Print "Issued by: " & cert.IssuerCN