| Crates.io | aescrypt-rs |
| lib.rs | aescrypt-rs |
| version | 0.2.0-rc.1 |
| created_at | 2025-11-27 11:49:21.631403+00 |
| updated_at | 2026-01-04 11:01:37.126384+00 |
| description | AES Crypt (v0-v3) Rust encryption/decryption library |
| homepage | |
| repository | https://github.com/Slurp9187/aescrypt-rs/tree/v020rc1 |
| max_upload_size | |
| id | 1953616 |
| size | 358,049 |
Fast, safe, streaming Rust implementation of the AES Crypt file format
read_version() — header-only version check in <1 μs (ideal for batch tools)secure-gate v0.7.0-rc.1 (enabled by default)unsafe in the core decryption path when zeroize is enabled#![no_std]-compatible coreAES Crypt was created and maintained for over two decades by Paul E. Jones. If you find AES Crypt (or this Rust port) useful, please consider supporting Paul directly:
| Operation | v0 | v1 | v2 | v3 |
|---|---|---|---|---|
| Decrypt | Yes | Yes | Yes | Yes |
| Encrypt | – | – | – | Yes |
| Detect version | Yes | Yes | Yes | Yes |
Why v3-only on write? Version 3 is the only secure, future-proof variant. Producing legacy formats today would be a security downgrade.
| Layer | Encryption | Integrity / KDF |
|---|---|---|
| Password → Master Key | – | PBKDF2-HMAC-SHA512 |
| Session Key + IV (48 B) | AES-256-CBC | HMAC-SHA256 |
| File Payload | AES-256-CBC | HMAC-SHA256 |
secure-gate types with automatic zeroizationAll public functions are thread-safe (Send + Sync). The library has no shared mutable state, making all operations safe for:
tokio::task::spawn_blocking or similaruse aescrypt_rs::{encrypt, PasswordString, constants::DEFAULT_PBKDF2_ITERATIONS};
use std::io::Cursor;
use std::thread;
let password = PasswordString::new("secret".to_string());
let data = b"large file data...";
// Spawn encryption in a thread
let handle = thread::spawn(move || {
let mut encrypted = Vec::new();
encrypt(
Cursor::new(data),
&mut encrypted,
&password,
DEFAULT_PBKDF2_ITERATIONS,
)
});
// Wait for completion or implement cancellation
let result = handle.join().unwrap()?;
# Ok::<(), aescrypt_rs::AescryptError>(())
For large files, operations may take significant time. Users requiring cancellation should spawn functions in threads and implement their own cancellation mechanism.
The library provides a minimal, focused API at the root level: High-level functions (99% of use cases):
encrypt() - Encrypt data to AES Crypt v3 formatdecrypt() - Decrypt AES Crypt files (v0-v3)read_version() - Quick version detection without full decryption
Key derivation:Pbkdf2Builder - Fluent builder for PBKDF2 key derivationderive_ackdf_key() - Low-level ACKDF for v0-v2 filesderive_pbkdf2_key() - Low-level PBKDF2 for v3 files
Types and constants:AescryptError - Comprehensive error typePasswordString and other secure types via aliases::*constants::*
Advanced access: Lower-level functions available via decryption::* and encryption::* module paths for custom flows.use aescrypt_rs::read_version;
use std::io::Cursor;
// v3 file header
let header = b"AES\x03\x00";
let version = read_version(Cursor::new(header))?;
assert_eq!(version, 3);
// v0 file header (3-byte)
let header = b"AES";
let version = read_version(Cursor::new(header))?;
assert_eq!(version, 0);
# Ok::<(), aescrypt_rs::AescryptError>(())
use aescrypt_rs::{encrypt, decrypt, PasswordString, constants::DEFAULT_PBKDF2_ITERATIONS};
use std::io::Cursor;
let pw = PasswordString::new("correct horse battery staple".to_string());
let data = b"top secret";
let mut ciphertext = Vec::new();
encrypt(Cursor::new(data), &mut ciphertext, &pw, DEFAULT_PBKDF2_ITERATIONS)?;
let mut plaintext = Vec::new();
decrypt(Cursor::new(&ciphertext), &mut plaintext, &pw)?;
assert_eq!(data, &plaintext[..]);
# Ok::<(), aescrypt_rs::AescryptError>(())
For custom key derivation with a fluent API:
use aescrypt_rs::{Pbkdf2Builder, PasswordString, aliases::Aes256Key32};
let password = PasswordString::new("my-secret-password".to_string());
// Use defaults (300k iterations, random salt)
let mut key = Aes256Key32::new([0u8; 32]);
Pbkdf2Builder::new()
.derive_secure(&password, &mut key)?;
// Or customize
let mut custom_key = Aes256Key32::new([0u8; 32]);
Pbkdf2Builder::new()
.with_iterations(500_000)
.with_salt([0x42; 16])
.derive_secure(&password, &mut custom_key)?;
// Or get a new key directly
let derived_key = Pbkdf2Builder::new()
.derive_secure_new(&password)?;
# Ok::<(), aescrypt_rs::AescryptError>(())
For custom decryption/encryption flows, access lower-level functions via module paths:
use aescrypt_rs::{
decryption::{extract_session_data, StreamConfig, read_file_version},
encryption::{derive_setup_key, encrypt_session_block},
aliases::{Aes256Key32, Iv16, PasswordString},
constants::DEFAULT_PBKDF2_ITERATIONS,
};
use std::io::Cursor;
let mut reader = Cursor::new(b"encrypted data...");
let version = read_file_version(&mut reader)?;
let password = PasswordString::new("password".to_string());
// Read public IV from file header (example placeholder)
let public_iv = Iv16::new([0u8; 16]);
let mut setup_key = Aes256Key32::new([0u8; 32]);
// derive_setup_key(&password, &public_iv, version, &mut setup_key)?;
let mut session_iv = Iv16::new([0u8; 16]);
let mut session_key = Aes256Key32::new([0u8; 32]);
extract_session_data(&mut reader, version, &public_iv, &setup_key, &mut session_iv, &mut session_key)?;
// Continue custom decryption with StreamConfig::V3, etc.
# Ok::<(), aescrypt_rs::AescryptError>(())
Configuration constants are available via the constants module:
use aescrypt_rs::constants::{
DEFAULT_PBKDF2_ITERATIONS, // 300,000 (recommended default)
PBKDF2_MIN_ITER, // 1
PBKDF2_MAX_ITER, // 5,000,000
AESCRYPT_LATEST_VERSION, // 3
};
| Workload | Throughput |
|---|---|
| Decrypt 10 MiB | ~158 MiB/s |
| Encrypt 10 MiB (with KDF) | ~149 MiB/s |
| Round-trip 10 MiB | ~75 MiB/s |
| All benchmarks include full 300,000 PBKDF2 iterations when applicable. |
Note: For very large files (GB+), operations may take minutes. All functions are thread-safe and can be spawned in threads for parallel processing or custom cancellation implementations.
| Feature | Description |
|---|---|
zeroize (default) |
Enables automatic secure memory wiping on drop for aes crate and constant-time operations (ct_eq()). |
rand (default) |
Enables cryptographically secure random generation (required for encryption convenience methods). |
Feature Details:
zeroize is disabled, regular equality comparisons (==) are used (not constant-time, vulnerable to timing attacks).rand is disabled, encryption convenience methods are unavailable (decryption still works; encryption possible with custom RNG).--no-default-features.[dependencies]
aescrypt-rs = "0.2.0-rc.1"
See CHANGELOG.md for a list of changes.
Licensed under MIT or Apache-2.0 at your option.
aescrypt-rs — the modern, safe, and future-proof way to handle AES Crypt files in Rust.