Function simplecrypt::decrypt[][src]

pub fn decrypt(
    data: &[u8],
    passphrase: &[u8]
) -> Result<Vec<u8>, DecryptionError>
Expand description

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:

indexusage
0 - 15salt
16 - 39nonce
40 - 55mac
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())
);