Skip to main content

encrypt_with_secret_key_and_aad

Function encrypt_with_secret_key_and_aad 

Source
pub fn encrypt_with_secret_key_and_aad(
    data: &[u8],
    key: &SecretKey,
    aad: &[u8],
    version: CiphertextVersion,
) -> Result<Ciphertext>
Expand description

Returns a Ciphertext from cleartext data and a SecretKey with additional authenticated data.

§Arguments

  • data - The data to encrypt.
  • key - The SecretKey to use. Generate one with generate_secret_key.
  • aad - Additional data to authenticate alongside the ciphertext.
  • version - Version of the library to encrypt with. Use CiphertextVersion::Latest if you’re not dealing with shared data.

§Returns

Returns a Ciphertext containing the encrypted data, which also authenticates the aad argument.

§Example

use devolutions_crypto::ciphertext::{ encrypt_with_secret_key_and_aad, CiphertextVersion };
use devolutions_crypto::key::{ generate_secret_key, KeyVersion };

let data = b"somesecretdata";
let aad = b"somepublicdata";
let key = generate_secret_key(KeyVersion::Latest);

let encrypted_data = encrypt_with_secret_key_and_aad(data, &key, aad, CiphertextVersion::Latest).unwrap();