Sample code for 30+ languages & platforms
DataFlex

Load a PFX from an Encoded String

See more PFX/P12 Examples

Demonstrates Pfx.LoadPfxEncoded, which decodes text using a named binary encoding (such as base64) and loads the resulting bytes as a PFX / PKCS#12 container.

Background. This is useful when the PKCS#12 data has been transported or stored as printable text, such as base64.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoPfx
    String sPassword
    String sEncodedPfx
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatPfx)) To hoPfx
    If (Not(IsComObjectCreated(hoPfx))) Begin
        Send CreateComObject of hoPfx
    End

    //  The PFX password should come from a secure source rather than being hard-coded.
    Move "myPfxPassword" To sPassword

    //  Decode the base64 text into PFX / PKCS#12 bytes and load them.  Common encodings include base64
    //  and hex.
    Move "MIIKrAIBAzCCCm...base64-encoded-pfx..." To sEncodedPfx
    Get ComLoadPfxEncoded Of hoPfx sEncodedPfx "base64" sPassword To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPfx To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComNumCerts Of hoPfx To iTemp1
    Showln "Loaded " iTemp1 " certificate(s)."


End_Procedure