Sample code for 30+ languages & platforms
Node.js

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.

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

    var certStore = new chilkat.CertStore();

    // 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 chilkat.Cert();
    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();

}

chilkatExample();