Sample code for 30+ languages & platforms
React Native Requires Chilkat v10.1.2+

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 React Native Downloads

React Native
import { Cert, CertStore } from '@chilkat/react-native'

function chilkatExample() {
  const certStore = new CertStore();

  // On MacOS and iOS, the OpenSmartcard method opens the Keychain.
  // The argument passed to OpenSmartcard is ignored.
  try {
    certStore.openSmartcard('');
  } catch {
    console.log(certStore.lastErrorText);
    return;
  }

  const numCerts = certStore.numCertificates;
  console.log(`numCerts = ${numCerts}`);

  const cert = new Cert();
  let 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()) {
      console.log('key type is RSA');
    }

    if (cert.isEcdsa()) {
      console.log('key type is ECDSA');
    }

    console.log(`has private key: ${cert.hasPrivateKey()}`);
    console.log('----');
    i++;
  }

  certStore.closeCertStore();
}