Sample code for 30+ languages & platforms
VBScript

Upgrade a Plain TCP Connection to TLS

See more Socket/SSL/TLS Examples

Demonstrates Socket.ConvertToSsl, which upgrades an already-connected plain TCP socket to TLS by performing a client-side TLS handshake over the existing connection.

Background. This supports STARTTLS-style upgrades, where a protocol begins in plaintext and switches to TLS at a defined point. Perform the protocol-specific negotiation first, then call ConvertToSsl.

Chilkat VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

set socket = CreateObject("Chilkat.Socket")

'  Connect as plain TCP (no TLS yet).
bTls = 0
maxWaitMs = 5000
success = socket.Connect("example.com",5000,bTls,maxWaitMs)
If (success = 0) Then
    outFile.WriteLine(socket.LastErrorText)
    WScript.Quit
End If

'  At the point where the application protocol permits a STARTTLS-style upgrade, perform any required
'  negotiation, then upgrade the existing connection to TLS with a client-side handshake.
success = socket.ConvertToSsl()
If (success = 0) Then
    outFile.WriteLine(socket.LastErrorText)
    WScript.Quit
End If

outFile.WriteLine("Connection upgraded to TLS.")

outFile.Close