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

Verfies an RSA Signature

See more Apple Keychain Examples

Verifies an RSA signature against the original data.

Chilkat Rust Downloads

Rust

// The following data was signed by the following example:
// RSA Sign using a Private Key on a USB Token or Smartcard
let bd = chilkat::BinData::new();
for i in 0..=100 {
    let _ = bd.append_encoded("000102030405060708090A0B0C0D0E0F", "hex");
}

// Load the signature
let bd_sig = chilkat::BinData::new();
if bd_sig.load_file("rsaSignatures/test1.sig").is_err() {
    println!("Failed to load the RSA signature");
    return;
}

// Get the public key to be used for signature verification.
let pub_key = chilkat::PublicKey::new();
if pub_key.load_from_file("rsaKeys/chilkat-rsa-2048.pem").is_err() {
    println!("{}", pub_key.last_error_text());
    return;
}

let rsa = chilkat::Rsa::new();
if rsa.use_public_key(&pub_key).is_err() {
    println!("{}", rsa.last_error_text());
    return;
}

// Verify the hash of the data against the signature.
// We pass in the original data.  Internally, the hash is generated
// and used to validate the signature.
// Validating the RSA signature means two things:  
// (1) the original data is exactly what was signed, and 
// (2) it was signed by the owner of the RSA private key.

if rsa.verify_bd(&bd, "sha256", &bd_sig).is_err() {
    println!("{}", rsa.last_error_text());
    println!("Signature invalid.");
} else {
    println!("Signature valid.");
}