Swift
Swift
Find Certificate by SHA1 Thumbprint
See more Cert Store Examples
Demonstrates how to find a certificate having the specified hexadecimal SHA1 thumbprint.Note: Requires Chilkat v10.1.2 or later.
Chilkat Swift Downloads
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
}
// Find the certificate having a specific SHA1 thumbprint.
let json = CkoJsonObject()!
var hexThumbprint: String? = "767192374BE3C1512D2CB80734926D40E96D6DC2"
json.updateString(jsonPath: "thumbprint", value: hexThumbprint)
let cert = CkoCert()!
success = certStore.findCert(json: json, cert: cert)
if success == true {
// Show the full distinguished name of the certificate.
print("Found: \(cert.subjectDN!)")
}
else {
print("Not found.")
}
}