(C++) Load PFX/P12 File into Certificate Store Object
Demonstrates how to load a .pfx/.p12 into a certificate store object.
#include <CkCertStore.h>
#include <CkCert.h>
void ChilkatSample(void)
{
CkCertStore certStore;
// This only loads the contents of the PFX file into the certStore object.
// It is not importing the PFX into the Windows certificate stores.
const char *pfxPassword = "badssl.com";
bool success = certStore.LoadPfxFile("qa_data/pfx/badssl.com-client.p12",pfxPassword);
if (success == false) {
std::cout << certStore.lastErrorText() << "\r\n";
return;
}
// Examine each certificate (loaded from the PFX) in this certStore object
int numCerts = certStore.get_NumCertificates();
int i = 0;
while (i < numCerts) {
CkCert *cert = certStore.GetCertificate(i);
std::cout << "hasPrivateKey=" << cert->HasPrivateKey() << ", " << cert->subjectCN() << "\r\n";
delete cert;
i = i + 1;
}
}
|