Sample code for 30+ languages & platforms
PureBasic

Load PFX/P12 from a Base64 Encoded PFX File

See more PFX/P12 Examples

Demonstrates how to call LoadPfxEncoded.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkBinData.pb"
IncludeFile "CkPfx.pb"

Procedure ChilkatExample()

    success.i = 0

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

    success = CkBinData::ckLoadFile(bd,"qa_data/pfx/cert_test123.pfx")
    If success <> 1
        Debug "Failed to load PFX file."
        CkBinData::ckDispose(bd)
        ProcedureReturn
    EndIf

    ; Get the bytes contained in the PFX in base64 format:
    strBase64.s = CkBinData::ckGetEncoded(bd,"base64")

    ; The base64 looks like this:  "MIIbEAIBAzCCGswGCSqGSIb3DQEHAaCCGr0Eghq5MIIatTCCBg..."
    Debug strBase64

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

    ; Load the PFX from the base64 string
    password.s = "test123"
    success = CkPfx::ckLoadPfxEncoded(pfx,strBase64,"base64",password)
    If success <> 1
        Debug CkPfx::ckLastErrorText(pfx)
        CkBinData::ckDispose(bd)
        CkPfx::ckDispose(pfx)
        ProcedureReturn
    EndIf

    Debug "success"


    CkBinData::ckDispose(bd)
    CkPfx::ckDispose(pfx)


    ProcedureReturn
EndProcedure