Sample code for 30+ languages & platforms
Swift

Load PFX (PKCS#12) and List Certificates

See more Certificates Examples

Loads a PFX file (.pfx, .p12) and iterates over the certificates found within.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let certStore = CkoCertStore()!

    var pfxPath: String? = "/Users/chilkat/testData/pfx/chilkat_ssl.pfx"
    var pfxPassword: String? = "test"
    success = certStore.loadPfxFile(path: 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(index: i, cert: cert)

        print("\(i): (Common Name) \(cert.subjectCN!)")
        print("\(i): (Serial Number) \(cert.serialNumber!)")
        print("\(i): (Distinguished Name) \(cert.subjectDN!)")

        i = i + 1
    }


}