Sample code for 30+ languages & platforms
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 C Downloads

C
#include <C_CkCertStore.h>
#include <C_CkCert.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkCertStore certStore;
    const char *pfxPath;
    const char *pfxPassword;
    int numCerts;
    HCkCert cert;
    int i;

    success = FALSE;

    certStore = CkCertStore_Create();

    pfxPath = "/Users/chilkat/testData/pfx/chilkat_ssl.pfx";
    pfxPassword = "test";
    success = CkCertStore_LoadPfxFile(certStore,pfxPath,pfxPassword);
    if (success != TRUE) {
        printf("%s\n",CkCertStore_lastErrorText(certStore));
        CkCertStore_Dispose(certStore);
        return;
    }

    numCerts = CkCertStore_getNumCertificates(certStore);

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

    cert = CkCert_Create();
    i = 0;
    while (i < numCerts) {
        CkCertStore_GetCert(certStore,i,cert);

        printf("%d: (Common Name) %s\n",i,CkCert_subjectCN(cert));
        printf("%d: (Serial Number) %s\n",i,CkCert_serialNumber(cert));
        printf("%d: (Distinguished Name) %s\n",i,CkCert_subjectDN(cert));

        i = i + 1;
    }



    CkCertStore_Dispose(certStore);
    CkCert_Dispose(cert);

    }