JavaScript
JavaScript
Apple Keychain - List Certs on Smartcards and USB Tokens
See more Apple Keychain Examples
Iterates over the certificatse on connected smartcards and USB tokens via the Apple Keychain.
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.
var success = false;
var certStore = new CkCertStore();
// On MacOS and iOS, the OpenSmartcard method opens the Keychain.
// The argument passed to OpenSmartcard is ignored.
success = certStore.OpenSmartcard("");
if (success == false) {
console.log(certStore.LastErrorText);
return;
}
var numCerts = certStore.NumCertificates;
console.log("numCerts = " + numCerts);
var cert = new CkCert();
var i = 0;
while (i < numCerts) {
// Note: Chilkat also gets the associated private key if it exists.
// You can simply use the cert in other places in Chilkat where a cert w/ private key is required.
certStore.GetCert(i,cert);
console.log(cert.SubjectDN);
console.log(cert.SubjectCN);
console.log(cert.SerialNumber);
if (cert.IsRsa() == true) {
console.log("key type is RSA");
}
if (cert.IsEcdsa() == true) {
console.log("key type is ECDSA");
}
console.log("has private key: " + cert.HasPrivateKey());
console.log("----");
i = i+1;
}
certStore.CloseCertStore();