(Unicode C++) Find Certificate by Serial Number
Demonstrates how to find a certificate having the specified hexadecimal serial number.
Note: Requires Chilkat v10.1.2 or later.
#include <CkCertStoreW.h>
#include <CkJsonObjectW.h>
#include <CkCertW.h>
void ChilkatSample(void)
{
CkCertStoreW certStore;
// This example will search the certs on connected USB tokens and smartcards.
const wchar_t *argNotUsed = L"";
bool success = certStore.OpenSmartcard(argNotUsed);
if (success == false) {
wprintf(L"%s\n",certStore.lastErrorText());
return;
}
// Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
const wchar_t *hexSerial = L"48FC93B46055948D36A7C98A89D69416";
CkJsonObjectW json;
json.UpdateString(L"serial",hexSerial);
CkCertW cert;
success = certStore.FindCert(json,cert);
if (success == true) {
// Show the serial number and subject CN
wprintf(L"Found: %s, %s\n",cert.serialNumber(),cert.subjectCN());
}
else {
wprintf(L"Not found.\n");
}
}
|