Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

Get Public Key from Certificate PEM

See more Certificates Examples

Loads a certificate from a PEM file and gets the cert's public key.

Chilkat Rust Downloads

Rust

let cert = chilkat::Cert::new();

if cert.load_from_file("qa_data/certs/someCert.pem").is_err() {
    println!("{}", cert.last_error_text());
    return;
}

// Get the certificate's public key:
let pubkey = chilkat::PublicKey::new();
let _ = cert.get_public_key(&pubkey);

println!("{}", pubkey.get_pem(false).unwrap_or_default());

// OK.. we have the public key which can be used in other Chilkat classes/methods...