[][src]Function enc_file::decrypt_chacha

pub fn decrypt_chacha(
    enc: Vec<u8>,
    key: &str
) -> Result<Vec<u8>, Box<dyn Error>>

Decrypts ciphertext (Vec) with a key (&str) using XChaCha20Poly1305 (24-byte nonce as compared to 12-byte in ChaCha20Poly1305). Panics with wrong key. Returns result (cleartext as Vec).

Examples

use enc_file::{encrypt_chacha, decrypt_chacha};

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

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

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