Sample code for 30+ languages & platforms
DataFlex

Set a TLS Client Certificate from a PFX

See more Socket/SSL/TLS Examples

Demonstrates Socket.SetSslClientCertPfx, which loads and configures a TLS client certificate and private key from a PFX/P12 file.

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoSocket
    String sPfxPassword
    Boolean iBTls
    Integer iMaxWaitMs
    String sTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatSocket)) To hoSocket
    If (Not(IsComObjectCreated(hoSocket))) Begin
        Send CreateComObject of hoSocket
    End

    //  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.
    Move "myPfxPassword" To sPfxPassword

    //  Load and configure the TLS client certificate and private key from a PFX/P12 file.  Configure the
    //  client certificate before connecting.
    Get ComSetSslClientCertPfx Of hoSocket "qa_data/client.pfx" sPfxPassword To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoSocket To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Move True To iBTls
    Move 5000 To iMaxWaitMs
    Get ComConnect Of hoSocket "example.com" 5000 iBTls iMaxWaitMs To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoSocket To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Connected with mutual TLS."


End_Procedure