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

Duplicate openssl dgst -sha256 -verify pubKey.pem -signature signature.sig in.dat

See more OpenSSL Examples

Demonstrates how to duplicate this OpenSSL command:
openssl dgst -sha256 -verify pubKey.pem -signature signature.sig in.dat
The in.dat file contains the original data that was signed, and can contain text or binary data of any type. The above OpenSSL command does the following:
  1. Creates a SHA256 digest of the contents of the input file.
  2. Verifies the SHA256 digest using the public key.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let pub_key = chilkat::PublicKey::new();

// Load the public key from an PEM file:
if pub_key.load_from_file("pubKey.pem").is_err() {
    println!("{}", pub_key.last_error_text());
    return;
}

// Load the data of the original file that was signed.
let bd_file_data = chilkat::BinData::new();
let _ = bd_file_data.load_file("in.dat").is_ok();

// Load the signature.
let bd_sig = chilkat::BinData::new();
let _ = bd_sig.load_file("signature.sig").is_ok();

let rsa = chilkat::Rsa::new();

// Import the public key into the RSA component:
if rsa.use_public_key(&pub_key).is_err() {
    println!("{}", rsa.last_error_text());
    return;
}

// OpenSSL uses big-endian.
rsa.set_little_endian(false);

if rsa.verify_bd(&bd_file_data, "sha256", &bd_sig).is_err() {
    println!("{}", rsa.last_error_text());
    println!("The signature was invalid.");
    return;
}

println!("The signature was verified.");