(C++) Load PFX (PKCS#12) and List Certificates
Loads a PFX file (.pfx, .p12) and iterates over the certificates found within. Note: This example requires Chilkat v10.1.2 or greater.
#include <CkCertStore.h>
#include <CkCert.h>
void ChilkatSample(void)
{
CkCertStore certStore;
bool success;
const char *pfxPath = "/Users/chilkat/testData/pfx/chilkat_ssl.pfx";
const char *pfxPassword = "test";
success = certStore.LoadPfxFile(pfxPath,pfxPassword);
if (success != true) {
std::cout << certStore.lastErrorText() << "\r\n";
return;
}
int numCerts = certStore.get_NumCertificates();
std::cout << "PFX contains " << numCerts << " certificates" << "\r\n";
CkCert cert;
int i = 0;
while (i < numCerts) {
certStore.GetCert(i,cert);
std::cout << i << ": (Common Name) " << cert.subjectCN() << "\r\n";
std::cout << i << ": (Serial Number) " << cert.serialNumber() << "\r\n";
std::cout << i << ": (Distinguished Name) " << cert.subjectDN() << "\r\n";
i = i + 1;
}
}
|