Sample code for 30+ languages & platforms
PureBasic

Export a PFX as PEM Text

See more PFX/P12 Examples

Demonstrates Pfx.ToPem, which exports all private keys and certificates currently held by the object as PEM-formatted text.

Background. Certificates are written as standard BEGIN CERTIFICATE blocks. This converts PKCS#12 material into the widely used PEM format.

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"
    success = CkPfx::ckLoadPfxFile(pfx,"qa_data/identity.pfx",password)
    If success = 0
        Debug CkPfx::ckLastErrorText(pfx)
        CkPfx::ckDispose(pfx)
        ProcedureReturn
    EndIf

    ;  Export all private keys and certificates currently held by the object as PEM-formatted text.
    pem.s = CkPfx::ckToPem(pfx)
    If CkPfx::ckLastMethodSuccess(pfx) = 0
        Debug CkPfx::ckLastErrorText(pfx)
        CkPfx::ckDispose(pfx)
        ProcedureReturn
    EndIf

    Debug pem


    CkPfx::ckDispose(pfx)


    ProcedureReturn
EndProcedure