Function encrypt

Source
pub fn encrypt(
    plaintext: impl AsRef<[u8]>,
    passphrase: impl AsRef<[u8]>,
) -> Result<Vec<u8>>
Available on crate feature alloc only.
Expand description

Encrypts plaintext and into a newly allocated Vec.

This uses the recommended Argon2 parameters according to the OWASP Password Storage Cheat Sheet created by Params::default. This also uses the Argon2 type created by Algorithm::default and the Argon2 version created by Version::default.

This is a convenience function for using Encryptor::new and Encryptor::encrypt_to_vec.

§Errors

Returns Err if the Argon2 context is invalid.

§Examples

let data = b"Hello, world!\n";
let passphrase = "passphrase";

let ciphertext = abcrypt::encrypt(data, passphrase).unwrap();