[−][src]Function simplecrypt::decrypt
pub fn decrypt(
data: &[u8],
passphrase: &[u8]
) -> Result<Vec<u8>, DecryptionError>
Decrypt the given data with the argon2id13 deriviation of the passphrase. Returns the decrypted data on success, or an empty tuple on failure.
The given byte slice is interpreted like this:
index | usage |
---|---|
0 - 15 | salt |
16 - 39 | nonce |
40 - 55 | mac |
56 - | data |
Examples
let encrypted_data = [ // salt 169, 41, 29, 81, 36, 11, 117, 33, 247, 2, 145, 245, 198, 17, 216, 16, 67, 46, 223, 109, 57, 110, 209, 163, 185, 122, 239, 245, 174, 208, 142, 227, // nonce 139, 139, 32, 147, 90, 92, 168, 229, 127, 92, 65, 153, 127, 38, 125, 144, 115, 104, 101, 187, 207, 130, 203, 39, // actual data 109, 12, 45, 42, 204, 139, 17, 130, 30, 97, 142, 213, 183, 126, 152, 226, 251, 225, 134, 201, 192, 202, 226, 71, 115, 95, 152, 71, 69, 246, 165, 147, 251, 106, 86, 47, 89, 30, ]; assert_eq!( Ok("lord ferris says: you shall not use Go".as_bytes().to_vec()), decrypt(&encrypted_data, "lul no generics".as_bytes()) );