Sample code for 30+ languages & platforms
Xojo Plugin

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 Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

Dim certStore As 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) Then
    System.DebugLog(certStore.LastErrorText)
    Return
End If

Dim numCerts As Int32
numCerts = certStore.NumCertificates
System.DebugLog("numCerts = " + Str(numCerts))

Dim cert As New Chilkat.Cert
Dim i As Int32
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.
    success = certStore.GetCert(i,cert)
    System.DebugLog(cert.SubjectDN)
    System.DebugLog(cert.SubjectCN)
    System.DebugLog(cert.SerialNumber)
    If (cert.IsRsa() = True) Then
        System.DebugLog("key type is RSA")
    End If

    If (cert.IsEcdsa() = True) Then
        System.DebugLog("key type is ECDSA")
    End If

    System.DebugLog("has private key: " + Str(cert.HasPrivateKey()))
    System.DebugLog("----")
    i = i + 1
Wend

success = certStore.CloseCertStore()