6 releases

0.2.0 Sep 15, 2022
0.1.4 May 9, 2022
0.1.2 Jan 24, 2022
0.1.1 Oct 31, 2021

#1462 in Cryptography

Download history 138/week @ 2023-12-31 31/week @ 2024-01-07 65/week @ 2024-01-14 55/week @ 2024-01-21 66/week @ 2024-01-28 40/week @ 2024-02-04 29/week @ 2024-02-11 159/week @ 2024-02-18 149/week @ 2024-02-25 59/week @ 2024-03-03 122/week @ 2024-03-10 53/week @ 2024-03-17 91/week @ 2024-03-24 64/week @ 2024-03-31 58/week @ 2024-04-07 45/week @ 2024-04-14

263 downloads per month

MIT/Apache

39KB
938 lines

aead-io

Provides a wrapper around a Write/Read object and a StreamPrimitive to provide an easy interface for doing correct encryption.

let key = b"my very super super secret key!!".into();
let plaintext = b"hello world!";

let ciphertext = {
    let mut ciphertext = Vec::default();
    let mut writer = EncryptBE32BufWriter::<ChaCha20Poly1305, _, _>::new(
        key,
        &Default::default(), // please use a better nonce ;)
        Vec::with_capacity(128),
        &mut ciphertext,
    )
    .unwrap();
    writer.write_all(plaintext)?;
    writer.flush()?;
    ciphertext
};

let decrypted = {
    let mut reader = DecryptBE32BufReader::<ChaCha20Poly1305, _, _>::new(
        key,
        Vec::with_capacity(256),
        ciphertext.as_slice(),
    )
    .unwrap();
    let mut out = Vec::new();
    let _ = reader.read_to_end(&mut out).unwrap();
    out
};

assert_eq!(decrypted, plaintext);
#

no_std

This package is compatible with no_std environments. Just disable the default features, and implement the Buffer, CappedBuffer, ResizeBuffer, Write and Read accordingly. There should be some default implementations for Vec<u8> and byte slices

License: MIT OR Apache-2.0

Dependencies

~320KB