Module openssl::envelope

source ·
Expand description

Envelope encryption.

Example

use openssl::rsa::Rsa;
use openssl::envelope::Seal;
use openssl::pkey::PKey;
use openssl::symm::Cipher;

let rsa = Rsa::generate(2048).unwrap();
let key = PKey::from_rsa(rsa).unwrap();

let cipher = Cipher::aes_256_cbc();
let mut seal = Seal::new(cipher, &[key]).unwrap();

let secret = b"My secret message";
let mut encrypted = vec![0; secret.len() + cipher.block_size()];

let mut enc_len = seal.update(secret, &mut encrypted).unwrap();
enc_len += seal.finalize(&mut encrypted[enc_len..]).unwrap();
encrypted.truncate(enc_len);

Structs

  • Represents an EVP_Open context.
  • Represents an EVP_Seal context.