PrivateBox
PrivateBox provides a small and easy to use API to encrypt your data. It is meant to do one thing, be a simple wrapper and validator around the RustCrypto XChaCha20Poly1305 AEAD encryption algorithm.
PrivateBox is inspired/based off of Cocoon. PrivateBox is meant to be a smaller API, more flexible with associated data, and uses XChaCha for random nonces.
Generating a key
The examples just use array generation for the key to keep the code duplication down. However, keys should be random or pseudo-random (aka derived from something like a password).
Example:
use ;
let mut key = ;
OsRng.fill_bytes;
Detached Encryption/Decryption
Detached encryption/decryption methods compute in place to avoid re-allocations. It returns a prefix (the nonce and tag) that is used for decryption. This is suitable for a no_std
build, when you want to avoid re-allocations of data, and if you want to manage serialization yourself.
Example:
let mut privatebox = new;
let mut message = *b"secret data";
let assoc_data = *b"plain text";
let detached_prefix = privatebox.encrypt_detached?;
assert_ne!;
privatebox.decrypt_detached?;
assert_eq!;
See the docs for examples and more information.
PrivateBox Container
The encrypt/decrypt methods handle serialization for you and returns a container. It enables the easy use of stored associated data and separate associated data. It is much simpler to use than detached encryption/decryption. It uses alloc
(enabled by default).
Example:
let mut privatebox = new;
t header = &;
let metadata = &;
let wrapped = privatebox.encrypt.expect;
let = privatebox.decrypt.expect;
assert_eq!;
assert_eq!;
See the docs for examples and more information.