Sample code for 30+ languages & platforms
PureBasic

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

PureBasic
IncludeFile "CkPfx.pb"

Procedure ChilkatExample()

    success.i = 0

    pfx.i = CkPfx::ckCreate()
    If pfx.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ;  The PFX password should come from a secure source rather than being hard-coded.
    password.s = "myPfxPassword"

    ;  Decode the base64 text into PFX / PKCS#12 bytes and load them.  Common encodings include base64
    ;  and hex.
    encodedPfx.s = "MIIKrAIBAzCCCm...base64-encoded-pfx..."
    success = CkPfx::ckLoadPfxEncoded(pfx,encodedPfx,"base64",password)
    If success = 0
        Debug CkPfx::ckLastErrorText(pfx)
        CkPfx::ckDispose(pfx)
        ProcedureReturn
    EndIf

    Debug "Loaded " + Str(CkPfx::ckNumCerts(pfx)) + " certificate(s)."


    CkPfx::ckDispose(pfx)


    ProcedureReturn
EndProcedure