Sample code for 30+ languages & platforms
JavaScript

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.

Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

var certStore = new CkCertStore();

// This example will search the certs on connected USB tokens and smartcards.
var argNotUsed = "";
success = certStore.OpenSmartcard(argNotUsed);
if (success == false) {
    console.log(certStore.LastErrorText);
    return;
}

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

var cert = new CkCert();
success = certStore.FindCert(json,cert);
if (success == true) {
    // Show the serial number and subject CN
    console.log("Found: " + cert.SerialNumber + ", " + cert.SubjectCN);
}
else {
    console.log("Not found.");
}