Skip to main content

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
5//! and decryption 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: `base64(version[1] || algorithm[1] || salt[16] || nonce[12] || ciphertext)`.
12//!
13//! # Examples
14//!
15//! ```no_run
16//! use rskit_encryption::{Encryptor, Algorithm};
17//! use rskit_encryption::new_encryptor;
18//!
19//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
20//! let encryptor = new_encryptor(b"my-secret-key", Algorithm::AesGcm);
21//!
22//! let plaintext = b"sensitive data";
23//! let ciphertext = encryptor.encrypt(plaintext)?;
24//! let decrypted = encryptor.decrypt(&ciphertext)?;
25//!
26//! assert_eq!(decrypted, plaintext);
27//! # Ok(())
28//! # }
29//! ```
30
31pub mod aes_gcm;
32pub mod chacha20;
33pub mod traits;
34
35mod envelope;
36
37pub use aes_gcm::AesGcmEncryptor;
38pub use chacha20::ChaCha20Encryptor;
39pub use traits::{Algorithm, Encryptor};
40
41mod factory;
42
43pub use factory::new_encryptor;
44
45#[cfg(test)]
46mod tests;