Sample code for 30+ languages & platforms
PureBasic

Use a Certificate Vault for Chain Building

See more PFX/P12 Examples

Demonstrates Pfx.UseCertVault, which adds the certificates in an XmlCertVault to the set of sources available for later chain-building operations such as AddCert.

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. The call captures a point-in-time snapshot of the vault's certificates. Providing extra intermediate certificates lets Chilkat complete certificate chains when building a PFX.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkXmlCertVault.pb"
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.
    ;  Load additional certificates (such as intermediate CA certificates) into a certificate vault.
    vault.i = CkXmlCertVault::ckCreate()
    If vault.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkXmlCertVault::ckAddCertFile(vault,"qa_data/intermediate_ca.cer")
    If success = 0
        Debug CkXmlCertVault::ckLastErrorText(vault)
        CkPfx::ckDispose(pfx)
        CkXmlCertVault::ckDispose(vault)
        ProcedureReturn
    EndIf

    ;  Make the vault's certificates available as sources for later chain-building operations, such as
    ;  AddCert.  The call captures a point-in-time snapshot of the vault's certificates.
    success = CkPfx::ckUseCertVault(pfx,vault)
    If success = 0
        Debug CkPfx::ckLastErrorText(pfx)
        CkPfx::ckDispose(pfx)
        CkXmlCertVault::ckDispose(vault)
        ProcedureReturn
    EndIf

    Debug "Certificate vault registered as a chain-building source."


    CkPfx::ckDispose(pfx)
    CkXmlCertVault::ckDispose(vault)


    ProcedureReturn
EndProcedure