Sample code for 30+ languages & platforms
Swift

Apple Keychain - List Certificates

See more Apple Keychain Examples

Iterates over the certificates in the Apple Keychain.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let certStore = CkoCertStore()!

    // On MacOS and iOS, the OpenCurrentUserStore method opens the Keychain.
    // The argument passed to OpenCurrentUserStore is ignored.
    success = certStore.openCurrentUserStore(readOnly: false)
    if success == false {
        print("\(certStore.lastErrorText!)")
        return
    }

    var numCerts: Int = certStore.numCertificates.intValue
    print("numCerts = \(numCerts)")

    let cert = CkoCert()!
    var i: Int = 0
    while i < numCerts {
        certStore.getCert(index: i, cert: cert)
        print("\(cert.subjectDN!)")
        print("\(cert.subjectCN!)")
        print("\(cert.serialNumber!)")
        print("----")
        i = i + 1
    }

    certStore.close()

}