pub fn decrypt(
ciphertext: impl AsRef<[u8]>,
passphrase: impl AsRef<[u8]>
) -> Result<Vec<u8>>
Available on crate feature
alloc
only.Expand description
Decrypts ciphertext
and into a newly allocated Vec
.
This is a convenience function for using Decryptor::new
and
Decryptor::decrypt_to_vec
.
Errors
Returns Err
if any of the following are true:
ciphertext
is shorter than 128 bytes.- The magic number is invalid.
- The version number is the unrecognized scrypt version number.
- The scrypt parameters are invalid.
- The checksum of the header mismatch.
- The MAC (authentication tag) of the header is invalid.
- The MAC (authentication tag) of the scrypt encrypted data format is invalid.
Examples
let data = b"Hello, world!\n";
let ciphertext = include_bytes!("../tests/data/data.txt.scrypt");
let passphrase = "passphrase";
let plaintext = scryptenc::decrypt(ciphertext, passphrase).unwrap();