(Swift) Load PFX/P12 File into Certificate Store Object
Demonstrates how to load a .pfx/.p12 into a certificate store object. Note: This example requires Chilkat v10.1.2 or greater.
func chilkatTest() {
let certStore = CkoCertStore()!
// This only loads the contents of the PFX file into the certStore object.
// It is not importing the PFX into the Windows certificate stores.
var pfxPassword: String? = "badssl.com"
var success: Bool = certStore.loadPfxFile("qa_data/pfx/badssl.com-client.p12", password: pfxPassword)
if success == false {
print("\(certStore.lastErrorText!)")
return
}
// Examine each certificate (loaded from the PFX) in this certStore object
let cert = CkoCert()!
var numCerts: Int = certStore.numCertificates.intValue
var i: Int = 0
while i < numCerts {
certStore.getCert(i, cert: cert)
print("hasPrivateKey=\(cert.hasPrivateKey()), \(cert.subjectCN!)")
i = i + 1
}
}
|