Sample code for 30+ languages & platforms
C++

Find Certificate by Serial Number

See more Cert Store Examples

Demonstrates how to find a certificate having the specified hexadecimal serial number.

Note: Requires Chilkat v10.1.2 or later.

Chilkat C++ Downloads

C++
#include <CkCertStore.h>
#include <CkJsonObject.h>
#include <CkCert.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkCertStore certStore;

    // This example will search the certs on connected USB tokens and smartcards.
    const char *argNotUsed = "";
    success = certStore.OpenSmartcard(argNotUsed);
    if (success == false) {
        std::cout << certStore.lastErrorText() << "\r\n";
        return;
    }

    // Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
    const char *hexSerial = "48FC93B46055948D36A7C98A89D69416";
    CkJsonObject json;
    json.UpdateString("serial",hexSerial);

    CkCert cert;
    success = certStore.FindCert(json,cert);
    if (success == true) {
        // Show the serial number and subject CN
        std::cout << "Found: " << cert.serialNumber() << ", " << cert.subjectCN() << "\r\n";
    }
    else {
        std::cout << "Not found." << "\r\n";
    }
    }