Function psa_crypto::operations::cipher::encrypt
source · pub fn encrypt(
key_id: Id,
alg: Cipher,
plaintext: &[u8],
iv: &[u8],
ciphertext: &mut [u8]
) -> Result<usize>
Expand description
Encrypt a short message with a key
The encrypted message is written in ciphertext
. The function returns the number of bytes written.
Example
psa_crypto::init().unwrap();
let my_key = generate(attributes, None).unwrap();
let alg = Cipher::CbcNoPadding;
let iv = vec![0; 16];
let mut encrypted_message = vec![0; MESSAGE.len()];
let size = encrypt(my_key, alg, &MESSAGE, &iv, &mut encrypted_message).unwrap();