Sample code for 30+ languages & platforms
B4X 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 B4X Downloads

B4X
Dim success As Boolean = False

Dim certStore As ChilkatCertStore
certStore.Initialize

'  On MacOS and iOS, the OpenSmartcard method opens the Keychain.
'  The argument passed to OpenSmartcard is ignored.
success = certStore.OpenSmartcard("")
If success = False Then
    Log(certStore.LastErrorText)
    Return
End If


Dim numCerts As Int = certStore.NumCertificates
Log("numCerts = " & numCerts)

Dim cert As ChilkatCert
cert.Initialize("cert")
Dim i As Int = 0
Do 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)
    Log(cert.SubjectDN)
    Log(cert.SubjectCN)
    Log(cert.SerialNumber)
    If cert.IsRsa = True Then
        Log("key type is RSA")
    End If

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

    Log("has private key: " & cert.HasPrivateKey)
    Log("----")
    i = i + 1
Loop

certStore.CloseCertStore