(PureBasic) Load PFX/P12 File into Certificate Store Object
Demonstrates how to load a .pfx/.p12 into a certificate store object.
IncludeFile "CkCert.pb"
IncludeFile "CkCertStore.pb"
Procedure ChilkatExample()
certStore.i = CkCertStore::ckCreate()
If certStore.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; This only loads the contents of the PFX file into the certStore object.
; It is not importing the PFX into the Windows certificate stores.
pfxPassword.s = "badssl.com"
success.i = CkCertStore::ckLoadPfxFile(certStore,"qa_data/pfx/badssl.com-client.p12",pfxPassword)
If success = 0
Debug CkCertStore::ckLastErrorText(certStore)
CkCertStore::ckDispose(certStore)
ProcedureReturn
EndIf
; Examine each certificate (loaded from the PFX) in this certStore object
numCerts.i = CkCertStore::ckNumCertificates(certStore)
i.i = 0
While i < numCerts
cert.i = CkCertStore::ckGetCertificate(certStore,i)
Debug "hasPrivateKey=" + Str(CkCert::ckHasPrivateKey(cert)) + ", " + CkCert::ckSubjectCN(cert)
CkCert::ckDispose(cert)
i = i + 1
Wend
CkCertStore::ckDispose(certStore)
ProcedureReturn
EndProcedure
|