| Crates.io | rustfuscator |
| lib.rs | rustfuscator |
| version | 1.0.0 |
| created_at | 2025-05-08 10:00:53.874786+00 |
| updated_at | 2025-05-08 10:00:53.874786+00 |
| description | A text obfuscation library using AES-GCM encryption |
| homepage | |
| repository | https://github.com/IQooLogic/rustfuscator |
| max_upload_size | |
| id | 1665087 |
| size | 37,884 |
The rustfuscator package provides functionality for Rust applications to securely encode and decode sensitive strings, such as passwords or API keys, making them safer to store in configuration files or transmit. It uses robust cryptographic methods to ensure data protection.
Internally, it employs:
The obfuscated output includes the version, salt, IV, and ciphertext, typically separated by a configurable separator (default is $), allowing for reliable unobfuscation later.
The Obfuscate function is non-deterministic. This means calling it multiple times with the exact same input text and passphrase will produce different output strings each time. This is intentional and enhances security, as it relies on generating a unique random salt and a unique random Initialization Vector (IV) for every encryption operation.
The package combines several standard, well-regarded cryptographic techniques to protect the data:
AES-GCM (Advanced Encryption Standard - Galois/Counter Mode):
encrypt and decrypt functions explicitly use aes.NewCipher and cipher.NewGCM to perform AES-GCM encryption and decryption.PBKDF2 (Password-Based Key Derivation Function 2):
generateSalt) means that even if two users use the same passphrase, the derived keys and the resulting obfuscated strings will be different. This prevents attackers from using precomputed tables (like rainbow tables) to crack multiple passphrases at once.deriveKey function uses pbkdf2.Key from the golang.org/x/crypto/pbkdf2 package, specifically with sha256.New as the hash function, a random salt generated per operation, and 1000 iterations to derive a 32-byte (256-bit) key suitable for AES.Random Salt and IV (Initialization Vector):
generateSalt function creates a random salt of configurable length, and genCryptoKey creates a random 12-byte IV before each encryption. Both are encoded and stored alongside the ciphertext in the final output string.In summary, the package doesn't invent new cryptography but correctly applies standard, well-vetted algorithms (AES-GCM, PBKDF2 with SHA256) and best practices (unique salts and IVs) to provide strong protection against unauthorized access and tampering, assuming a strong passphrase is used.
Add this to your Cargo.toml:
[dependencies]
rustfuscator = "1.0.0"
use obfuscator::Obfuscator;
fn main() {
// Create an obfuscator with a passphrase
let obfuscator = Obfuscator::new("my-secure-passphrase".as_bytes());
// Obfuscate text
let obfuscated = obfuscator.obfuscate("Hello, World!").unwrap();
println!("Obfuscated: {}", obfuscated);
// Unobfuscate text
let unobfuscated = obfuscator.unobfuscate(&obfuscated).unwrap();
println!("Unobfuscated: {}", unobfuscated);
}
use obfuscator::Obfuscator;
fn main() {
// Create an obfuscator with custom configuration
let obfuscator = Obfuscator::new("passphrase".as_bytes())
.with_salt_length(16) // Custom salt length
.with_separator("#"); // Custom separator
// Use the obfuscator
let obfuscated = obfuscator.obfuscate("Secret message").unwrap();
let unobfuscated = obfuscator.unobfuscate(&obfuscated).unwrap();
assert_eq!(unobfuscated, "Secret message");
}
This project is licensed under the MIT License - see the LICENSE file for details.