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