Sample code for 30+ languages & platforms
Rust

Load Certificate from .cer and Private Key from .pem

See more Certificates Examples

Load a certificate from a .cer and its associated private key from a .pem.

Chilkat Rust Downloads

Rust

let cert = chilkat::Cert::new();
if cert.load_from_file("C:/certs_and_keys/Certificate.cer").is_err() {
    println!("{}", cert.last_error_text());
    return;
}

let sb_pem = chilkat::StringBuilder::new();
if sb_pem.load_file("C:/certs_and_keys/PrivateKey.pem", "utf-8").is_err() {
    println!("Failed to load private key PEM");
    return;
}

if cert.set_private_key_pem(&sb_pem.get_as_string().unwrap_or_default()).is_err() {
    println!("{}", cert.last_error_text());
    return;
}

println!("The certificate and associated private key are now loaded and ready for signing.");