Rust Requires Chilkat v11.0.0+
Rust
RSA Sign utf-8 Byte Representation of String
See more RSA Examples
Demontstrates how to sign the utf-8 byte representation of a string.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Load an RSA private key for signing.
let priv_key = chilkat::PrivateKey::new();
if priv_key.load_encrypted_pem_file("qa_data/pem/rsa_passwd.pem", "passwd").is_err() {
println!("{}", priv_key.last_error_text());
return;
}
let rsa = chilkat::Rsa::new();
if rsa.use_private_key(&priv_key).is_err() {
println!("{}", rsa.last_error_text());
return;
}
let original_data = "This is the string to be hashed an RSA signed.".to_string();
// Indicate that we want the utf-8 byte representation of the string to be signed
rsa.set_charset("utf-8");
// We want the RSA signature in base64 format
rsa.set_encoding_mode("base64");
let sig_base64 = rsa.sign_string_enc(&original_data, "sha256").unwrap_or_default();
println!("{}", sig_base64);