Rust Requires Chilkat v11.0.0+
Rust
Duplicate openssl dgst -sha256 -sign private.pem -out sha256.sig in.dat
See more OpenSSL Examples
Demonstrates how to duplicate this OpenSSL command:openssl dgst -sha256 -sign private.pem -out sha256.sig in.datThe in.dat file can contain text or binary data of any type. The OpenSSL command does the following:
- Creates a SHA256 digest of the contents of the input file
- Signs the SHA256 digest using the private key.
Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let pkey = chilkat::PrivateKey::new();
// Load the private key from an PEM file:
if pkey.load_pem_file("private.pem").is_err() {
println!("{}", pkey.last_error_text());
return;
}
let rsa = chilkat::Rsa::new();
// Import the private key into the RSA component:
if rsa.use_private_key(&pkey).is_err() {
println!("{}", rsa.last_error_text());
return;
}
// OpenSSL uses big-endian.
rsa.set_little_endian(false);
// Load the file to be signed.
let bd_file_data = chilkat::BinData::new();
let _ = bd_file_data.load_file("in.dat").is_ok();
let bd_sig = chilkat::BinData::new();
if rsa.sign_bd(&bd_file_data, "sha256", &bd_sig).is_err() {
println!("{}", rsa.last_error_text());
return;
}
// Save the binary signature to a file.
if bd_sig.write_file("signature.sig").is_err() {
println!("Failed to write signature.sig.");
return;
}
println!("Success.");