(JavaScript) Find Certificate by Subject CN (Common Name)
Demonstrates how to find a certificate having the specified subject CN.
Note: Requires Chilkat v10.1.2 or later.
var success = false;
var certStore = new CkCertStore();
// This opens the Current User certificate store on Windows,
// On MacOS and iOS it opens the default Keychain.
var readOnly = false;
success = certStore.OpenCurrentUserStore(readOnly);
if (success == false) {
console.log(certStore.LastErrorText);
return;
}
// Find the certificate having a Subject CN = "Example ABC".
var json = new CkJsonObject();
json.UpdateString("CN","Example ABC");
var cert = new CkCert();
success = certStore.FindCert(json,cert);
if (success == true) {
// Show the full distinguished name of the certificate.
console.log("Found: " + cert.SubjectDN);
}
else {
console.log("Not found.");
}
|