Rust Requires Chilkat v11.0.0+
Rust
Use Base64 RSA Key to Encrypt
See more RSA Examples
Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let pubkey = chilkat::PublicKey::new();
if pubkey.load_base64("MIICdgIBADA ... A9PXLk+j5A==").is_err() {
println!("{}", pubkey.last_error_text());
return;
}
let rsa = chilkat::Rsa::new();
if rsa.use_public_key(&pubkey).is_err() {
println!("{}", rsa.last_error_text());
return;
}
rsa.set_encoding_mode("base64");
let encrypted_str = rsa.encrypt_string_enc("12345678", false).unwrap_or_default();
println!("{}", encrypted_str);