Expand description
Password-based authenticated encryption for byte slices and files.
cryptainer derives a 256-bit key from a password with Argon2id, encrypts
data with AES-256-GCM, and stores the result as salt || nonce || ciphertext.
§Examples
§Encrypt bytes
use cryptainer::encrypt_data;
let mut rng = rand::rng();
let data = encrypt_data("password", b"hello world", &mut rng)?;§Decrypt bytes
use cryptainer::{decrypt_data, encrypt_data};
let mut rng = rand::rng();
let encrypted = encrypt_data("password", b"hello world", &mut rng)?;
let plaintext = decrypt_data(&encrypted, "password")?;§Save and load files
use cryptainer::{decrypt_file, encrypt_data, save_file};
let mut rng = rand::rng();
let data = encrypt_data("password", b"secret", &mut rng)?;
save_file("secret.stuff", &data)?;
let plaintext = decrypt_file("secret.stuff", "password")?;Structs§
- Crypt
Data - Serialized encrypted data returned by
encrypt_data.
Enums§
- Crypt
Error - Errors returned by encryption, decryption, and file helpers.
Functions§
- decrypt_
data - Decrypts a buffer produced by
encrypt_dataorsave_file. - decrypt_
file - Reads an encrypted file from disk and decrypts it with
password. - encrypt_
data - Encrypts
plaintextwith a key derived frompassword. - save_
file - Writes encrypted data to disk in
salt || nonce || ciphertextorder.