(JavaScript) 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.
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.");
}
|