Sample code for 30+ languages & platforms
Rust

Duplicate openssl smime -decrypt -in some_file.dat.enc -binary -inform DER -inkey private.key -out some_file.dat

See more OpenSSL Examples

Demonstrates how to decrypt binary DER that was encrypted using the following openssl command:
openssl smime -encrypt -binary -aes-256-cbc -in some_file.dat -out some_file.dat.enc -outform DER cert.crt

Chilkat Rust Downloads

Rust

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

// Duplicates the following openssl command:
// openssl smime -decrypt -in hello.txt.enc -binary -inform DER -inkey private.key -out hello.txt

let cert = chilkat::Cert::new();
if cert.load_from_file("qa_data/openssl/EE.cer").is_err() {
    println!("{}", cert.last_error_text());
    return;
}

let bd = chilkat::BinData::new();
let _ = bd.load_file("qa_data/openssl/EE.key").is_ok();
// Assuming success..

let priv_key = chilkat::PrivateKey::new();
if priv_key.load_any_format(&bd, "").is_err() {
    println!("{}", priv_key.last_error_text());
    return;
}

let crypt = chilkat::Crypt2::new();
if crypt.set_decrypt_cert2(&cert, &priv_key).is_err() {
    println!("{}", crypt.last_error_text());
    return;
}

crypt.set_crypt_algorithm("PKI");
if crypt.ck_decrypt_file("qa_data/openssl/hello.txt.enc", "qa_output/hello.txt").is_err() {
    println!("{}", crypt.last_error_text());
    return;
}

println!("Success.");