(C++) Load PFX (PKCS#12) and List Certificates
Loads a PFX file (.pfx, .p12) and iterates over the certificates found within.
#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";
int i = 0;
while (i < numCerts) {
CkCert *cert = certStore.GetCertificate(i);
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";
delete cert;
i = i + 1;
}
}
|