| Crates.io | emixcrypto |
| lib.rs | emixcrypto |
| version | 0.6.0 |
| created_at | 2026-01-11 14:03:47.661788+00 |
| updated_at | 2026-01-11 14:03:47.661788+00 |
| description | Cryptographic utilities for EssentialMix, providing encryption, hashing, encoding, and random number generation |
| homepage | |
| repository | https://github.com/asm2025/essentialmix-rs |
| max_upload_size | |
| id | 2035861 |
| size | 97,047 |
emixcrypto provides comprehensive cryptographic utilities for the EssentialMix project, including encryption, hashing, encoding, and random number generation capabilities.
This crate implements a Rust-native cryptographic library based on the C# essentialMix.Cryptography project. It follows Rust best practices and idioms, providing a safe and efficient API for cryptographic operations.
use emixcrypto::QuickCipher;
// Hash a string
let hash = QuickCipher::hash("Hello, World!", "SHA256")?;
println!("Hash: {}", hash);
// Base64 encode
let encoded = QuickCipher::base64_encode("Hello, World!")?;
println!("Encoded: {}", encoded);
// Decode
let decoded = QuickCipher::base64_decode(&encoded)?;
println!("Decoded: {}", decoded);
use emixcrypto::{AesAlgorithm, SymmetricAlgorithm};
// Create an AES cipher
let mut cipher = AesAlgorithm::new()?;
// Generate key from passphrase
cipher.generate_key_from_passphrase("my-secret-passphrase", None, 10000)?;
cipher.generate_iv()?;
// Encrypt
let encrypted = cipher.encrypt_string("Secret message")?;
println!("Encrypted: {}", encrypted);
// Decrypt
let decrypted = cipher.decrypt_string(&encrypted)?;
println!("Decrypted: {}", decrypted);
use emixcrypto::RsaAlgorithm;
// Create RSA key pair
let mut rsa = RsaAlgorithm::new(2048)?;
// Encrypt
let encrypted = rsa.encrypt_string("Secret message")?;
// Decrypt
let decrypted = rsa.decrypt_string(&encrypted)?;
use emixcrypto::{Sha256Hash, HashAlgorithm};
let hasher = Sha256Hash::new();
let hash = hasher.compute_hash_string("Hello, World!")?;
println!("SHA-256: {}", hash);
The crate uses feature flags to allow you to include only the algorithms you need:
[dependencies]
emixcrypto = { path = "../crates/crypto", features = ["default"] }
Or for full functionality:
[dependencies]
emixcrypto = { path = "../crates/crypto", features = ["full"] }
The crate uses a custom CryptoError type that can be converted to emixcore::Error:
use emixcrypto::{CryptoError, Result};
fn my_function() -> Result<String> {
// Operations that may fail
Ok("success".to_string())
}
Key Management: Always use secure key storage. Keys are automatically zeroized when dropped (using the zeroize crate).
Random Number Generation: The crate uses ChaCha20 RNG, which is cryptographically secure.
Key Derivation: PBKDF2 is used for deriving keys from passphrases. Use a sufficient number of iterations (recommended: 100,000+).
IV Generation: Always use cryptographically secure random IVs. Never reuse IVs with the same key.
Legacy Algorithms: MD5 and SHA-1 are provided for legacy compatibility only. Use SHA-256 or SHA-512 for new code.
src/
├── lib.rs # Public API and re-exports
├── error.rs # Error types
├── traits.rs # Core traits (Algorithm, Encrypt, etc.)
├── settings.rs # Configuration types
├── symmetric/ # Symmetric encryption
│ ├── aes.rs
│ └── traits.rs
├── asymmetric/ # Asymmetric encryption
│ ├── rsa.rs
│ └── traits.rs
├── hash/ # Hash algorithms
│ ├── sha.rs
│ ├── md5.rs
│ └── hmac.rs
├── encoder/ # Encoding utilities
│ ├── base64.rs
│ └── numeric.rs
├── random/ # Random number generation
│ └── rng.rs
├── cipher/ # Special ciphers
│ └── vigenere.rs
└── service.rs # QuickCipher high-level service
See the examples/ directory (when available) for more comprehensive examples.
MIT (inherited from workspace)
This crate is part of the EssentialMix project. Please follow the project's contribution guidelines.