| Crates.io | shared-aes-enc |
| lib.rs | shared-aes-enc |
| version | 0.3.8 |
| created_at | 2025-06-16 16:57:04.140766+00 |
| updated_at | 2025-06-17 03:06:46.83508+00 |
| description | A shared AES encryption library providing secure encryption and decryption functionality |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1714509 |
| size | 21,576 |
A Rust library for shared-key AES encryption that combines two separate keys to create a derived encryption key using SHA3 hashing and bit manipulation techniques.
Add this to your Cargo.toml:
[dependencies]
shared-aes-enc = "0.3.7"
The library's main feature is encrypting data using two separate keys that are combined:
use shared_aes_enc::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let key1 = "alice_secret_key";
let key2 = "bob_secret_key";
let message = "Hello, World!";
// Encrypt string (returns base64-encoded result)
let encrypted = shared_key_encrypt(key1, key2, message)?;
println!("Encrypted: {}", encrypted);
// Decrypt back to original string
let decrypted = shared_key_decrypt(key1, key2, &encrypted)?;
println!("Decrypted: {}", decrypted);
assert_eq!(message, decrypted);
Ok(())
}
For encrypting raw bytes without base64 encoding:
use shared_aes_enc::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let key1 = "user_key";
let key2 = "server_key";
let data = b"Binary data to encrypt";
// Encrypt binary data
let encrypted_bytes = shared_key_encrypt_bytes(key1, key2, data)?;
// To decrypt, you'll need to use the lower-level decryption
// (Note: The library currently only provides string decryption)
Ok(())
}
Generate cryptographically secure random passwords:
use shared_aes_enc::*;
fn main() {
// Generate a 16-character random password
let password = generate_password(16);
println!("Generated password: {}", password);
// Generate a longer password
let long_password = generate_password(32);
println!("Long password: {}", long_password);
}
shared_key_encrypt(key1: &str, key2: &str, data: &str) -> Result<String, Box<dyn std::error::Error>>
shared_key_encrypt_bytes(key1: &str, key2: &str, data: &[u8]) -> Result<Vec<u8>, Box<dyn std::error::Error>>
shared_key_decrypt(key1: &str, key2: &str, encrypted_b64: &str) -> Result<String, Box<dyn std::error::Error>>
generate_password(length: usize) -> String
This library is particularly useful for:
⚠️ Important Security Notes:
aes (0.7.5) - AES block cipher implementationblock-modes (0.8.1) - Block cipher modes of operationsha3 (0.10.8) - SHA-3 cryptographic hash functionrand (0.9.1) - Random number generationbase64 (0.22.1) - Base64 encoding/decodingThis project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
Note: This library appears to be designed for educational purposes or CTF (Capture The Flag) challenges. For production cryptographic needs, consider using well-established libraries with authenticated encryption modes.