(Swift) Find Certificate by Subject CN (Common Name)
Demonstrates how to find a certificate having the specified subject CN.
Note: Requires Chilkat v10.1.2 or later.
func chilkatTest() {
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
var success: Bool = certStore.openCurrentUserStore(readOnly)
if success == false {
print("\(certStore.lastErrorText!)")
return
}
// Find the certificate having a Subject CN = "Example ABC".
let json = CkoJsonObject()!
json.update("CN", value: "Example ABC")
let cert = CkoCert()!
success = certStore.findCert(json, cert: cert)
if success == true {
// Show the full distinguished name of the certificate.
print("Found: \(cert.subjectDN!)")
}
else {
print("Not found.")
}
}
|