Sample code for 30+ languages & platforms
Swift

Iterate over Certificates in a Certificate Store

See more Cert Store Examples

Demonstrates how to iterate over the certificates in a certificate store.

Note: Requires Chilkat v10.1.2 or later.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let certStore = CkoCertStore()!

    // This opens the Current User certificate store on Windows,
    // On MacOS and iOS it opens the default Keychain.
    var readOnly: Bool = false
    success = certStore.openCurrentUserStore(readOnly: readOnly)
    if success == false {
        print("\(certStore.lastErrorText!)")
        return
    }

    let cert = CkoCert()!

    var numCerts: Int = certStore.numCertificates.intValue
    var i: Int = 0

    while (i < numCerts) {
        // Load the cert object with the Nth certificate.
        certStore.getCert(index: i, cert: cert)
        print("\(i): \(cert.subjectCN!)")
        i = i + 1
    }


}