Sample code for 30+ languages & platforms
Swift

Load PFX/P12 File into Certificate Store Object

Demonstrates how to load a .pfx/.p12 into a certificate store object.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    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"
    success = certStore.loadPfxFile(path: "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(index: i, cert: cert)
        print("hasPrivateKey=\(cert.hasPrivateKey()), \(cert.subjectCN!)")
        i = i + 1
    }


}