Rust
Rust
Decrypt2
See more MIME Examples
Demonstrates how to decrypt MIME using a certificate and private key where the certificate and its corresponding private key are stored in separate files -- a .cer for the certificate, and a .pem for the private key.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let mime = chilkat::Mime::new();
// Load the certificate from a .cer file.
let cert = chilkat::Cert::new();
if cert.load_from_file("aaworkarea/myCert.cer").is_err() {
println!("{}", cert.last_error_text());
return;
}
// Load the private key from an encrypted PEM file.
// (A private key can be loaded from other file formats also..)
let priv_key = chilkat::PrivateKey::new();
if priv_key.load_encrypted_pem_file("aaworkarea/myPrivateKey.pem", "myPassword").is_err() {
println!("{}", priv_key.last_error_text());
return;
}
if mime.load_mime_file("aaworkarea/encryptedMime.txt").is_err() {
println!("{}", mime.last_error_text());
return;
}
// Decrypt using the cert and associated private key
if mime.decrypt2(&cert, &priv_key).is_err() {
println!("{}", mime.last_error_text());
return;
}
// Save the S/MIME to a file.
if mime.save_mime("aaworkarea/decryptedMime.txt").is_err() {
println!("{}", mime.last_error_text());
return;
}
println!("success!");