Sample code for 30+ languages & platforms
PureBasic

Load a PFX from a File

See more PFX/P12 Examples

Demonstrates Pfx.LoadPfxFile, which loads a PFX / PKCS#12 container from a file path, using the supplied password to decrypt it.

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. A PFX (PKCS#12) container bundles one or more certificates together with their private keys. After loading, the certificates and keys can be enumerated and used.

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 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.
    password.s = "myPfxPassword"

    ;  Load a PFX / PKCS#12 container from a file.
    success = CkPfx::ckLoadPfxFile(pfx,"qa_data/identity.pfx",password)
    If success = 0
        Debug CkPfx::ckLastErrorText(pfx)
        CkPfx::ckDispose(pfx)
        ProcedureReturn
    EndIf

    Debug "Loaded " + Str(CkPfx::ckNumCerts(pfx)) + " certificate(s) and " + Str(CkPfx::ckNumPrivateKeys(pfx)) + " private key(s)."


    CkPfx::ckDispose(pfx)


    ProcedureReturn
EndProcedure