Sample code for 30+ languages & platforms
Rust

Example: Crypt2.ClearEncryptCerts method

Demonstrates how to call the ClearEncryptCerts method.

Chilkat Rust Downloads

Rust

let crypt = chilkat::Crypt2::new();

// Tell the crypt object to use 3 certificates.
// Do this by calling AddEncryptCert for each certificate.

let cert1 = chilkat::Cert::new();
// ...
// Load the cert from a source such as a .pfx/.p12 file, smart card, USB token, Apple keychain, Windows certificate store, etc.
// ...
crypt.add_encrypt_cert(&cert1);

let cert2 = chilkat::Cert::new();
// ...
crypt.add_encrypt_cert(&cert2);

let cert3 = chilkat::Cert::new();
// ...
crypt.add_encrypt_cert(&cert3);

// Params for public-key encryption to create PKCS7 enveloped-data
crypt.set_crypt_algorithm("pki");
crypt.set_pkcs7_crypt_alg("aes");
crypt.set_key_length(256);
crypt.set_oaep_hash("sha256");
crypt.set_oaep_padding(true);

let bd = chilkat::BinData::new();
// ...
let _ = crypt.encrypt_bd(&bd).is_ok();

// Let's say we now want to encrypt something else with different certs..
// First clear the encryption certs.
crypt.clear_encrypt_certs();

let cert4 = chilkat::Cert::new();
// ...
crypt.add_encrypt_cert(&cert4);

let cert5 = chilkat::Cert::new();
// ...
crypt.add_encrypt_cert(&cert5);

// ...
// ...

// Encrypt using cert4 and cert5.
let _ = crypt.encrypt_bd(&bd).is_ok();