Sample code for 30+ languages & platforms
Swift

ZATCA Load Certificate and Private Key from PEM Files

See more ZATCA Examples

Demonstrates how to load a certificate and private key from a pair of PEM files.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    // The LoadFromFile method will automatically detect the file format..
    let cert = CkoCert()!
    success = cert.load(fromFile: "qa_data/zatca/cert.pem")
    if success != true {
        print("\(cert.lastErrorText!)")
        return
    }

    print("\(cert.subjectCN!)")

    // Load the private key.
    let privKey = CkoPrivateKey()!
    success = privKey.loadPemFile(path: "qa_data/zatca/ec-secp256k1-priv-key.pem")
    if success != true {
        print("\(privKey.lastErrorText!)")
        return
    }

    print("Key Type: \(privKey.keyType!)")

    // Associate the private key with the certificate.
    success = cert.setPrivateKey(privKey: privKey)
    if success != true {
        print("\(cert.lastErrorText!)")
        return
    }

    print("Success.")

}