(Swift) Load PFX/P12 File into Certificate Store Object
Demonstrates how to load a .pfx/.p12 into a certificate store object.
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
var numCerts: Int = certStore.numCertificates.intValue
var i: Int = 0
while i < numCerts {
var cert: CkoCert? = certStore.getCertificate(i)
print("hasPrivateKey=\(cert!.hasPrivateKey()), \(cert!.subjectCN!)")
cert = nil
i = i + 1
}
}
|