Unicode C
Unicode C
Load PFX/P12 File into Certificate Store Object
Demonstrates how to load a .pfx/.p12 into a certificate store object.Chilkat Unicode C Downloads
#include <C_CkCertStoreW.h>
#include <C_CkCertW.h>
void ChilkatSample(void)
{
BOOL success;
HCkCertStoreW certStore;
const wchar_t *pfxPassword;
HCkCertW cert;
int numCerts;
int i;
success = FALSE;
certStore = CkCertStoreW_Create();
// 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 = L"badssl.com";
success = CkCertStoreW_LoadPfxFile(certStore,L"qa_data/pfx/badssl.com-client.p12",pfxPassword);
if (success == FALSE) {
wprintf(L"%s\n",CkCertStoreW_lastErrorText(certStore));
CkCertStoreW_Dispose(certStore);
return;
}
// Examine each certificate (loaded from the PFX) in this certStore object
cert = CkCertW_Create();
numCerts = CkCertStoreW_getNumCertificates(certStore);
i = 0;
while (i < numCerts) {
CkCertStoreW_GetCert(certStore,i,cert);
wprintf(L"hasPrivateKey=%d, %s\n",CkCertW_HasPrivateKey(cert),CkCertW_subjectCN(cert));
i = i + 1;
}
CkCertStoreW_Dispose(certStore);
CkCertW_Dispose(cert);
}