Sample code for 30+ languages & platforms
Swift

Load PFX/P12 from a Base64 Encoded PFX File

See more PFX/P12 Examples

Demonstrates how to call LoadPfxEncoded.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let bd = CkoBinData()!

    success = bd.loadFile(path: "qa_data/pfx/cert_test123.pfx")
    if success != true {
        print("Failed to load PFX file.")
        return
    }

    // Get the bytes contained in the PFX in base64 format:
    var strBase64: String? = bd.getEncoded(encoding: "base64")

    // The base64 looks like this:  "MIIbEAIBAzCCGswGCSqGSIb3DQEHAaCCGr0Eghq5MIIatTCCBg..."
    print("\(strBase64!)")

    let pfx = CkoPfx()!

    // Load the PFX from the base64 string
    var password: String? = "test123"
    success = pfx.loadEncoded(encodedData: strBase64, encoding: "base64", password: password)
    if success != true {
        print("\(pfx.lastErrorText!)")
        return
    }

    print("success")

}