Java
Chilkat2 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
import com.chilkatsoft.chilkat2.Cert;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.PrivateKey;
public class ChilkatExample {
public static void main(String[] args) {
// The LoadFromFile method will automatically detect the file format..
Cert cert = new Cert();
try {
cert.loadFromFile("qa_data/zatca/cert.pem");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println(cert.getSubjectCN());
// Load the private key.
PrivateKey privKey = new PrivateKey();
try {
privKey.loadPemFile("qa_data/zatca/ec-secp256k1-priv-key.pem");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Key Type: " + privKey.getKeyType());
// Associate the private key with the certificate.
try {
cert.setPrivateKey(privKey);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Success.");
}
}