Skip to main content

Crate cryptainer

Crate cryptainer 

Source
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§

CryptData
Serialized encrypted data returned by encrypt_data.

Enums§

CryptError
Errors returned by encryption, decryption, and file helpers.

Functions§

decrypt_data
Decrypts a buffer produced by encrypt_data or save_file.
decrypt_file
Reads an encrypted file from disk and decrypts it with password.
encrypt_data
Encrypts plaintext with a key derived from password.
save_file
Writes encrypted data to disk in salt || nonce || ciphertext order.