(Unicode C++) Load PFX (PKCS#12) and List Certificates
Loads a PFX file (.pfx, .p12) and iterates over the certificates found within.
#include <CkCertStoreW.h>
#include <CkCertW.h>
void ChilkatSample(void)
{
CkCertStoreW certStore;
bool success;
const wchar_t *pfxPath = L"/Users/chilkat/testData/pfx/chilkat_ssl.pfx";
const wchar_t *pfxPassword = L"test";
success = certStore.LoadPfxFile(pfxPath,pfxPassword);
if (success != true) {
wprintf(L"%s\n",certStore.lastErrorText());
return;
}
int numCerts = certStore.get_NumCertificates();
wprintf(L"PFX contains %d certificates\n",numCerts);
int i = 0;
while (i < numCerts) {
CkCertW *cert = certStore.GetCertificate(i);
wprintf(L"%d: (Common Name) %s\n",i,cert->subjectCN());
wprintf(L"%d: (Serial Number) %s\n",i,cert->serialNumber());
wprintf(L"%d: (Distinguished Name) %s\n",i,cert->subjectDN());
delete cert;
i = i + 1;
}
}
|