Sample code for 30+ languages & platforms
PureBasic

Load P7B and List Certificates

Demonstrates how to load a .p7b containing certificates and accesses each individual certificate.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkPem.pb"
IncludeFile "CkCert.pb"

Procedure ChilkatExample()

    success.i = 0

    ; This example assumes the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    success = 0

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

    ; Load the .p7b from a file.
    success = CkPem::ckLoadP7bFile(pem,"/Users/chilkat/testData/p7b/myCerts.p7b")
    If success <> 1
        Debug CkPem::ckLastErrorText(pem)
        CkPem::ckDispose(pem)
        ProcedureReturn
    EndIf

    i.i
    numCerts.i = CkPem::ckNumCerts(pem)
    If numCerts = 0
        Debug ("Error: Expected the .p7b to contain certificates.")
        CkPem::ckDispose(pem)
        ProcedureReturn
    EndIf

    ; Access each certificate and show the DN (Distinguished Name)
    For i = 1 To numCerts
        cert.i = CkPem::ckGetCert(pem,i - 1)
        Debug Str(i) + ": " + CkCert::ckSubjectDN(cert)
        CkCert::ckDispose(cert)

    Next


    CkPem::ckDispose(pem)


    ProcedureReturn
EndProcedure