Sample code for 30+ languages & platforms
PowerBuilder

Set a TLS Client Certificate from a Cert Object

See more Socket/SSL/TLS Examples

Demonstrates Socket.SetSslClientCert, which configures a certificate as the client certificate for subsequent TLS connections. The certificate must have access to its private key.

The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.

Background. Configure the client certificate before connecting. Use client certificates only when the server requests or requires client-certificate authentication (mutual TLS).

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Socket
string ls_PfxPassword
oleobject loo_Cert
integer li_BTls
integer li_MaxWaitMs

li_Success = 0

loo_Socket = create oleobject
li_rc = loo_Socket.ConnectToNewObject("Chilkat.Socket")
if li_rc < 0 then
    destroy loo_Socket
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  The file path is relative to the application's current working directory.  An absolute path
//  may also be used.  Supply the path appropriate to your own environment.
//  The PFX password should come from a secure source rather than being hard-coded.
ls_PfxPassword = "myPfxPassword"
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")

li_Success = loo_Cert.LoadPfxFile("qa_data/client.pfx",ls_PfxPassword)
if li_Success = 0 then
    Write-Debug loo_Cert.LastErrorText
    destroy loo_Socket
    destroy loo_Cert
    return
end if

//  Configure the client certificate before connecting.  Use this only when the server requests or
//  requires client-certificate authentication (mutual TLS).
li_Success = loo_Socket.SetSslClientCert(loo_Cert)
if li_Success = 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    destroy loo_Cert
    return
end if

li_BTls = 1
li_MaxWaitMs = 5000
li_Success = loo_Socket.Connect("example.com",5000,li_BTls,li_MaxWaitMs)
if li_Success = 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    destroy loo_Cert
    return
end if

Write-Debug "Connected with mutual TLS."


destroy loo_Socket
destroy loo_Cert