Sample code for 30+ languages & platforms
Rust

Duplicate openssl smime -encrypt -binary -aes-256-cbc -in some_file.dat -out some_file.dat.enc -outform DER cert.crt

See more OpenSSL Examples

Demonstrates how to encrypt to binary DER using 256-bit AES (CBC mode) as the underlying symmetric encryption algorithm, to produce PKCS7 enveloped data (binary DER).

Duplicates 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.

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/hello.txt").is_ok();
// Assuming success..

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

crypt.set_crypt_algorithm("PKI");

// Indicate the underlying symmetric encryption to be used:
crypt.set_pkcs7_crypt_alg("aes");
crypt.set_key_length(256);
crypt.set_cipher_mode("cbc");

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

println!("Success.");