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

RSA Import Public Key from Certificate PEM

See more RSA Examples

Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.

Chilkat Rust Downloads

Rust

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

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

let pub_key = chilkat::PublicKey::new();
let _ = cert.get_public_key(&pub_key);

let rsa = chilkat::Rsa::new();
let _ = rsa.use_public_key(&pub_key);

rsa.set_encoding_mode("base64");
let encrypted_str = rsa.encrypt_string_enc("hello", false).unwrap_or_default();
println!("encrypted string = {}", encrypted_str);