Function psa_crypto::operations::asym_encryption::encrypt [−][src]
pub fn encrypt(
key_id: Id,
alg: AsymmetricEncryption,
plaintext: &[u8],
salt: Option<&[u8]>,
ciphertext: &mut [u8]
) -> Result<usize>
Expand description
Encrypt a short message with a key pair or public 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 = AsymmetricEncryption::RsaPkcs1v15Crypt;
let buffer_size = attributes.asymmetric_encrypt_output_size(alg).unwrap();
let mut encrypted_message = vec![0; buffer_size];
let size = encrypt(my_key,
alg,
&MESSAGE,
None,
&mut encrypted_message).unwrap();
encrypted_message.resize(size, 0);