Swift
Swift
Find Certificate by Serial Number
See more Cert Store Examples
Demonstrates how to find a certificate having the specified hexadecimal serial number.Note: Requires Chilkat v10.1.2 or later.
Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
let certStore = CkoCertStore()!
// This example will search the certs on connected USB tokens and smartcards.
var argNotUsed: String? = ""
success = certStore.openSmartcard(csp: argNotUsed)
if success == false {
print("\(certStore.lastErrorText!)")
return
}
// Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
var hexSerial: String? = "48FC93B46055948D36A7C98A89D69416"
let json = CkoJsonObject()!
json.updateString(jsonPath: "serial", value: hexSerial)
let cert = CkoCert()!
success = certStore.findCert(json: json, cert: cert)
if success == true {
// Show the serial number and subject CN
print("Found: \(cert.serialNumber!), \(cert.subjectCN!)")
}
else {
print("Not found.")
}
}