6 releases (3 breaking)
0.4.1 | Dec 19, 2023 |
---|---|
0.4.0 | Dec 18, 2023 |
0.3.1 | Dec 4, 2023 |
0.2.0 | Dec 2, 2023 |
0.1.0 | Nov 30, 2023 |
#963 in Cryptography
Used in 2 crates
52KB
736 lines
Secured-Cipher Library
Overview
secured-cipher
is a Rust library offering an implementation of the ChaCha20
and Poly1305
algorithms. It provides both high-level and low-level cryptographic functionalities through a common interface.
Features
- High-level interfaces for
ChaCha20
cipher andPoly1305
authenticator. - Common
Cipher
interface for encryption and decryption operations. core
module with low-level crypto operations- Flexible usage with support for both raw and high-level cryptographic operations.
Basic Encryption and Decryption Example
Encrypt and decrypt data using the ChaCha20 cipher:
use secured_cipher::Cipher;
let key: [u8; 32] = [0; 32]; // Your key
let nonce: [u8; 12] = [0; 12]; // Your nonce
let data: &[u8] = b"Your data here"; // Data to be encrypted
let mut cipher = Cipher::default();
cipher.init(&key, &nonce);
// Encrypt and decrypt
let encrypted_data = cipher.encrypt(data);
let decrypted_data = cipher.decrypt(&encrypted_data);
// Sign
let signed_secret_envelope = cipher.sign(b"your readable header", &encrypted_data);
// Decrypt and verify
let verified_decrypted_data = cipher.decrypt_and_verify(&signed_secret_envelope);
assert!(verified_decrypted_data.is_ok());
println!("Decrypted and verified data: {:?}", verified_decrypted_data.unwrap());
Installation
Add secured-cipher
to your Cargo.toml:
[dependencies]
secured-cipher = "~0.3.1"
Dependencies
~2MB
~40K SLoC