Function enc_file::decrypt_aes

source ·
pub fn decrypt_aes(enc: Vec<u8>, key: &str) -> Result<Vec<u8>, Box<dyn Error>>
Expand description

Decrypts ciphertext (Vec) with a key (&str) using AES256 GCM SIV. Panics with wrong key. Returns result (cleartext as Vec).

§Examples

use enc_file::{encrypt_aes, decrypt_aes};

let text = b"This a test";
let key: &str = "an example very very secret key.";
// encrypt_aes takes plaintext as Vec<u8>. Text needs to be transformed into vector
let text_vec = text.to_vec();

let ciphertext = encrypt_aes(text_vec, key).unwrap();
assert_ne!(&ciphertext, &text);

let plaintext = decrypt_aes(ciphertext, key).unwrap();
assert_eq!(format!("{:?}", text), format!("{:?}", plaintext));