Sample code for 30+ languages & platforms
Unicode C

Load PFX (PKCS#12) and List Certificates

See more Certificates Examples

Loads a PFX file (.pfx, .p12) and iterates over the certificates found within.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkCertStoreW.h>
#include <C_CkCertW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkCertStoreW certStore;
    const wchar_t *pfxPath;
    const wchar_t *pfxPassword;
    int numCerts;
    HCkCertW cert;
    int i;

    success = FALSE;

    certStore = CkCertStoreW_Create();

    pfxPath = L"/Users/chilkat/testData/pfx/chilkat_ssl.pfx";
    pfxPassword = L"test";
    success = CkCertStoreW_LoadPfxFile(certStore,pfxPath,pfxPassword);
    if (success != TRUE) {
        wprintf(L"%s\n",CkCertStoreW_lastErrorText(certStore));
        CkCertStoreW_Dispose(certStore);
        return;
    }

    numCerts = CkCertStoreW_getNumCertificates(certStore);

    wprintf(L"PFX contains %d certificates\n",numCerts);

    cert = CkCertW_Create();
    i = 0;
    while (i < numCerts) {
        CkCertStoreW_GetCert(certStore,i,cert);

        wprintf(L"%d: (Common Name) %s\n",i,CkCertW_subjectCN(cert));
        wprintf(L"%d: (Serial Number) %s\n",i,CkCertW_serialNumber(cert));
        wprintf(L"%d: (Distinguished Name) %s\n",i,CkCertW_subjectDN(cert));

        i = i + 1;
    }



    CkCertStoreW_Dispose(certStore);
    CkCertW_Dispose(cert);

    }