Sample code for 30+ languages & platforms
Java

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

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    // The LoadFromFile method will automatically detect the file format..
    CkCert cert = new CkCert();
    success = cert.LoadFromFile("qa_data/zatca/cert.pem");
    if (success != true) {
        System.out.println(cert.lastErrorText());
        return;
        }

    System.out.println(cert.subjectCN());

    // Load the private key.
    CkPrivateKey privKey = new CkPrivateKey();
    success = privKey.LoadPemFile("qa_data/zatca/ec-secp256k1-priv-key.pem");
    if (success != true) {
        System.out.println(privKey.lastErrorText());
        return;
        }

    System.out.println("Key Type: " + privKey.keyType());

    // Associate the private key with the certificate.
    success = cert.SetPrivateKey(privKey);
    if (success != true) {
        System.out.println(cert.lastErrorText());
        return;
        }

    System.out.println("Success.");
  }
}