rskit_encryption/lib.rs
1#![warn(missing_docs)]
2//! Symmetric encryption utilities with AES-256-GCM and ChaCha20-Poly1305 support.
3//!
4//! This crate provides a unified interface for symmetric encryption and decryption
5//! of sensitive data using either AES-256-GCM (default, with hardware acceleration)
6//! or ChaCha20-Poly1305 (modern, performant without AES-NI).
7//!
8//! Keys are derived from passphrases using PBKDF2-SHA256 with 600,000 iterations
9//! and a random 16-byte salt per encryption operation.
10//!
11//! Ciphertext format:
12//! `base64(version[1] || algorithm[1] || salt[16] || nonce[12] || ciphertext)`.
13//!
14//! # Examples
15//!
16//! ```no_run
17//! use rskit_encryption::{Encryptor, Algorithm};
18//! use rskit_encryption::new_encryptor;
19//!
20//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
21//! let encryptor = new_encryptor(b"my-secret-key", Algorithm::AesGcm);
22//!
23//! let plaintext = b"sensitive data";
24//! let ciphertext = encryptor.encrypt(plaintext)?;
25//! let decrypted = encryptor.decrypt(&ciphertext)?;
26//!
27//! assert_eq!(decrypted, plaintext);
28//! # Ok(())
29//! # }
30//! ```
31
32pub mod aes_gcm;
33pub mod chacha20;
34pub mod traits;
35
36mod envelope;
37
38pub use aes_gcm::AesGcmEncryptor;
39pub use chacha20::ChaCha20Encryptor;
40pub use traits::{Algorithm, Encryptor};
41
42mod factory;
43
44pub use factory::new_encryptor;
45
46#[cfg(test)]
47mod tests;