chacha20_poly1305 stream wrapper

Contains a writable stream that wraps another, applying the chacha20_poly1305 cipher to the input before writing for either encryption or decryption.

Usage

Encrypt and decrypt message with an in-memory buffer. ```rust // Generate random key and IV for the operations. let (key, iv) = chacha20stream::keygen();

let input = "Hello world!";

// Encryption into a new Vec<u8>. let mut sink = Sink::encrypt(Vec::new(), key, iv).expect("Failed to create encryptor"); sink.writeall(input.asbytes()).unwrap(); sink.flush().unwrap(); // flush also clears the in-memory buffer if there is left over data in it.

let outputencrypted = sink.intoinner();

// Decryption into a new Vec<u8> let mut sink = Sink::decrypt(Vec::new(), key, iv).expect("Failed to create decryptor"); sink.writeall(&outputencrypted[..]).unwrap(); sink.flush().unwrap();

let outputdecrypted = sink.intoinner();

asserteq!(&outputdecrypted[..], input.as_bytes()); ```

Features

License

MIT