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

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

void ChilkatSample(void)
    {
    BOOL success;
    HCkCertStore certStore;
    BOOL readOnly;
    HCkJsonObject jsonE;
    HCkCert cert;

    success = FALSE;

    certStore = CkCertStore_Create();

    // The "AddressBook" is the "Other People" certificate store as shown in certmgr.msc
    readOnly = TRUE;
    success = CkCertStore_OpenWindowsStore(certStore,"CurrentUser","AddressBook",readOnly);
    if (success != TRUE) {
        printf("%s\n",CkCertStore_lastErrorText(certStore));
        CkCertStore_Dispose(certStore);
        return;
    }

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

    cert = CkCert_Create();
    success = CkCertStore_FindCert(certStore,jsonE,cert);
    if (success == FALSE) {
        printf("%s\n",CkCertStore_lastErrorText(certStore));
        CkCertStore_Dispose(certStore);
        CkJsonObject_Dispose(jsonE);
        CkCert_Dispose(cert);
        return;
    }

    printf("Found certificate: %s\n",CkCert_subjectDN(cert));


    CkCertStore_Dispose(certStore);
    CkJsonObject_Dispose(jsonE);
    CkCert_Dispose(cert);

    }