Sample code for 30+ languages & platforms
Go

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 Go Downloads

Go
    success := false

    // The LoadFromFile method will automatically detect the file format..
    cert := chilkat.NewCert()
    success = cert.LoadFromFile("qa_data/zatca/cert.pem")
    if success != true {
        fmt.Println(cert.LastErrorText())
        cert.DisposeCert()
        return
    }

    fmt.Println(cert.SubjectCN())

    // Load the private key.
    privKey := chilkat.NewPrivateKey()
    success = privKey.LoadPemFile("qa_data/zatca/ec-secp256k1-priv-key.pem")
    if success != true {
        fmt.Println(privKey.LastErrorText())
        cert.DisposeCert()
        privKey.DisposePrivateKey()
        return
    }

    fmt.Println("Key Type: ", privKey.KeyType())

    // Associate the private key with the certificate.
    success = cert.SetPrivateKey(privKey)
    if success != true {
        fmt.Println(cert.LastErrorText())
        cert.DisposeCert()
        privKey.DisposePrivateKey()
        return
    }

    fmt.Println("Success.")

    cert.DisposeCert()
    privKey.DisposePrivateKey()