Sample code for 30+ languages & platforms
Rust

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

Rust

// The LoadFromFile method will automatically detect the file format..
let cert = chilkat::Cert::new();
if cert.load_from_file("qa_data/zatca/cert.pem").is_err() {
    println!("{}", cert.last_error_text());
    return;
}

println!("{}", cert.subject_cn());

// Load the private key.
let priv_key = chilkat::PrivateKey::new();
if priv_key.load_pem_file("qa_data/zatca/ec-secp256k1-priv-key.pem").is_err() {
    println!("{}", priv_key.last_error_text());
    return;
}

println!("Key Type: {}", priv_key.key_type());

// Associate the private key with the certificate.
if cert.set_private_key(&priv_key).is_err() {
    println!("{}", cert.last_error_text());
    return;
}

println!("Success.");