Sample code for 30+ languages & platforms
Unicode C

Find a Certificate in the "Other People" Windows Certificate Store

See more Certificates Examples

Demonstrates how to open the "Current User --> Other People" Windows certificate store, and locates a certificate matching an email address.

Chilkat Unicode C Downloads

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

void ChilkatSample(void)
    {
    BOOL success;
    HCkCertStoreW certStore;
    BOOL readOnly;
    HCkJsonObjectW jsonE;
    HCkCertW cert;

    success = FALSE;

    certStore = CkCertStoreW_Create();

    // The "AddressBook" is the "Other People" certificate store as shown in certmgr.msc
    readOnly = TRUE;
    success = CkCertStoreW_OpenWindowsStore(certStore,L"CurrentUser",L"AddressBook",readOnly);
    if (success != TRUE) {
        wprintf(L"%s\n",CkCertStoreW_lastErrorText(certStore));
        CkCertStoreW_Dispose(certStore);
        return;
    }

    // Find the certificate for the email address:
    jsonE = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(jsonE,L"email",L"joe@example.com");

    cert = CkCertW_Create();
    success = CkCertStoreW_FindCert(certStore,jsonE,cert);
    if (success == FALSE) {
        wprintf(L"%s\n",CkCertStoreW_lastErrorText(certStore));
        CkCertStoreW_Dispose(certStore);
        CkJsonObjectW_Dispose(jsonE);
        CkCertW_Dispose(cert);
        return;
    }

    wprintf(L"Found certificate: %s\n",CkCertW_subjectDN(cert));


    CkCertStoreW_Dispose(certStore);
    CkJsonObjectW_Dispose(jsonE);
    CkCertW_Dispose(cert);

    }