(Swift) Load PFX (PKCS#12) and List Certificates
Loads a PFX file (.pfx, .p12) and iterates over the certificates found within. Note: This example requires Chilkat v10.1.2 or greater.
func chilkatTest() {
let certStore = CkoCertStore()!
var success: Bool
var pfxPath: String? = "/Users/chilkat/testData/pfx/chilkat_ssl.pfx"
var pfxPassword: String? = "test"
success = certStore.loadPfxFile(pfxPath, password: pfxPassword)
if success != true {
print("\(certStore.lastErrorText!)")
return
}
var numCerts: Int = certStore.numCertificates.intValue
print("PFX contains \(numCerts) certificates")
let cert = CkoCert()!
var i: Int = 0
while i < numCerts {
certStore.getCert(i, cert: cert)
print("\(i): (Common Name) \(cert.subjectCN!)")
print("\(i): (Serial Number) \(cert.serialNumber!)")
print("\(i): (Distinguished Name) \(cert.subjectDN!)")
i = i + 1
}
}
|