IronCrypt
IronCrypt is a Command-Line Interface (CLI) tool and Rust library dedicated to secure password and data encryption. By combining the Argon2 hashing algorithm, AES-256-GCM encryption, and RSA for key management, IronCrypt provides a robust solution to ensure your application’s data confidentiality and password security.
Features
- Hybrid Encryption (RSA + AES): IronCrypt uses a smart combination of encryption methods. It encrypts your data with AES-256 (very fast and secure), and then encrypts the AES key itself with RSA. This is an industry-standard technique called "envelope encryption" that combines the best of both worlds: the speed of symmetric encryption and the secure key management of asymmetric encryption.
- State-of-the-Art Password Hashing: For passwords, IronCrypt uses Argon2, currently considered one of the most secure hashing algorithms in the world. It is specifically designed to resist modern GPU-based brute-force attacks, providing much greater security than older algorithms.
- Advanced Key Management: The built-in key versioning system (
-v v1,-v v2) and the dedicatedrotate-keycommand allow you to update your encryption keys over time. This automates the process of migrating to a new key without having to manually decrypt and re-encrypt all your data. IronCrypt can load both modern PKCS#8 keys and legacy PKCS#1 keys, ensuring broad compatibility. - Flexible Configuration: You can finely tune security parameters via the
ironcrypt.tomlfile, environment variables, or theIronCryptConfigstruct in code. This includes RSA key size and the computational "costs" of the Argon2 algorithm, allowing you to balance security and performance to fit your needs. - Comprehensive Data Encryption: IronCrypt is built to handle more than just passwords. It can encrypt any file (images, PDFs, documents), entire directories (by archiving them first), or any other data that can be represented as a stream of bytes.
- Dual Use (CLI and Library): IronCrypt is designed from the ground up to be dual-purpose. You can use it as a quick command-line tool for simple tasks, or integrate it as a library (crate) directly into your own Rust applications for more complex logic.
Workflows
Password Encryption/Decryption

This process ensures maximum security by combining robust hashing with Argon2 and hybrid encryption (called "envelope encryption") with AES and RSA.
1. Encryption Process (e.g., during user registration)
The goal here is not to encrypt the password itself, but to encrypt a unique fingerprint (a "hash") of that password. The plaintext password is never stored.
-
Password Hashing:
- The password provided by the user (e.g.,
"MyPassword123") is first passed through the Argon2 hashing algorithm. - Argon2 transforms it into a unique and non-reversible digital fingerprint (the "hash"). This algorithm is designed to be slow and memory-intensive, making it extremely resistant to modern brute-force attacks.
- The password provided by the user (e.g.,
-
Creating the Encryption Envelope:
- A new AES-256 symmetric encryption key is randomly generated. This key is for one-time use and will only be used for this operation.
- The Argon2 hash (created in step 1) is then encrypted using this AES key.
-
Securing the AES Key (the "seal" of the envelope):
- To be able to verify the password later, the AES key must be saved. Storing it in plaintext would be a security flaw.
- Therefore, the AES key is itself encrypted, but this time with your public RSA key. Only the holder of the corresponding private RSA key will be able to decrypt this AES key.
-
Storing the Secure Data:
- The final result is a structured JSON object that contains all the necessary information for future verification:
- The hash encrypted by AES.
- The AES key encrypted by RSA.
- The technical (public) parameters used for hashing and encryption (like the "salt" and "nonce").
- The version of the RSA key used for the seal.
- It is this JSON object that is securely stored in your database.
- The final result is a structured JSON object that contains all the necessary information for future verification:
2. Verification Process (e.g., during user login)
The goal here is to verify if the password provided by the user matches the stored one, without ever having to see it in plaintext.
-
Data Retrieval:
- The user logs in by providing their password (e.g.,
"MyPassword123"). - You retrieve the corresponding JSON object for this user from your database.
- The user logs in by providing their password (e.g.,
-
Opening the Envelope:
- Using your private RSA key, you decrypt the AES key contained in the JSON.
- Once the plaintext AES key is obtained, you use it to decrypt the original Argon2 hash.
-
Real-time Hashing and Comparison:
- The password just provided by the user for login is hashed in turn, using the exact same parameters (the "salt") as those stored in the JSON.
- The two hashes—the one just generated and the one decrypted from the database—are compared.
-
Verification Result:
- If the two hashes are identical, it proves that the provided password is correct. Access is granted.
- If they are different, the password is incorrect. Access is denied.
This workflow ensures that even if your database were compromised, the users' passwords would remain unusable by an attacker, as the original password is never stored there.
File Encryption/Decryption

This process also uses envelope encryption (AES + RSA) to ensure both performance and security.
1. Encryption Process
- Reading the file: The content of the file (e.g., an image, a PDF) is read into memory as binary data.
- Creating the envelope:
- A new one-time use AES-256 key is randomly generated.
- The binary data of the file is fully encrypted with this AES key.
- Sealing the envelope:
- The AES key is encrypted with your public RSA key.
- Storage: A JSON object is created, containing the encrypted file data, the encrypted AES key, and the necessary metadata. This JSON is then saved to a new file (e.g.,
my_document.enc).
2. Decryption Process
- Reading the encrypted file: The content of the
.encfile (the JSON) is read. - Opening the envelope:
- Your private RSA key is used to decrypt the AES key.
- The AES key is then used to decrypt the original binary data of the file.
- Saving the file: The decrypted binary data is written to a new file, thus restoring the original file.
Directory Encryption/Decryption

Encrypting an entire directory is based on the file encryption workflow, with an additional preparation step.
1. Encryption Process
- Archiving and Compression:
- The target directory is first read, and all its files and subdirectories are compressed into a single in-memory archive (a
.tar.gzfile).
- The target directory is first read, and all its files and subdirectories are compressed into a single in-memory archive (a
- Encrypting the archive:
- This
.tar.gzarchive is then treated as a simple binary file. - The file encryption process described above is applied to the archive.
- This
- Storage: The resulting JSON is saved to a single encrypted file.
2. Decryption Process
- Decrypting the archive:
- The file decryption process is used to retrieve the plaintext
.tar.gzarchive.
- The file decryption process is used to retrieve the plaintext
- Decompression and Extraction:
- The
.tar.gzarchive is then decompressed, and its contents are extracted to the destination directory, thus recreating the original structure and files.
- The
Installation
Prerequisites
- Rust (latest stable version recommended)
- Cargo (Rust's package manager)
Building and Running from Source
There are three main ways to run the ironcrypt command-line tool.
1. Using cargo run (Recommended for development)
This command compiles and runs the program in one step. Use -- to separate cargo's arguments from your program's arguments.
# Clone the repository
# Run the --help command
2. Building and running the executable directly
You can build the executable and then run it from its path in the target directory.
# Build the optimized release executable
# Run it from its path
3. Installing the binary (Recommended for usage)
This will install the ironcrypt command on your system, making it available from any directory. This is the best option for regular use.
# From the root of the project directory, run:
# Now you can use the command from anywhere
Usage
Command-Line Interface (CLI)
Here is a summary table of all available commands:
| Command | Alias | Description | Key Options |
|---|---|---|---|
generate |
Generates a new RSA key pair. | -v, --version <VERSION> -d, --directory <DIR> -s, --key-size <SIZE> |
|
encrypt |
Hashes and encrypts a password. | -w, --password <PASSWORD> -d, --public-key-directory <DIR> -v, --key-version <VERSION> |
|
decrypt |
Verifies an encrypted password. | -w, --password <PASSWORD> -k, --private-key-directory <DIR> -v, --key-version <VERSION> -f, --file <FILE> |
|
encrypt-file |
encfile, efile, ef |
Encrypts a binary file. | -i, --input-file <INPUT> -o, --output-file <OUTPUT> -d, --public-key-directory <DIR> -v, --key-version <VERSION> [-w, --password <PASSWORD>] |
decrypt-file |
decfile, dfile, df |
Decrypts a binary file. | -i, --input-file <INPUT> -o, --output-file <OUTPUT> -k, --private-key-directory <DIR> -v, --key-version <VERSION> [-w, --password <PASSWORD>] |
encrypt-dir |
encdir |
Encrypts an entire directory. | -i, --input-dir <INPUT> -o, --output-file <OUTPUT> -d, --public-key-directory <DIR> -v, --key-version <VERSION> [-w, --password <PASSWORD>] |
decrypt-dir |
decdir |
Decrypts an entire directory. | -i, --input-file <INPUT> -o, --output-dir <OUTPUT> -k, --private-key-directory <DIR> -v, --key-version <VERSION> [-w, --password <PASSWORD>] |
rotate-key |
rk |
Rotates encryption keys for encrypted data. | --old-version <OLD_V> --new-version <NEW_V> -k, --key-directory <DIR> --file <FILE> or --directory <DIR> |
A full list of commands and their arguments can be viewed by running ironcrypt --help. To get help for a specific command, run ironcrypt <command> --help.
generate
Generates a new RSA key pair (private and public).
Usage:
Example:
# Generate a new v2 key with a size of 4096 bits in the "my_keys" directory
encrypt
Hashes and encrypts a password.
Usage:
Example:
# Encrypt a password using the v1 public key
decrypt
Decrypts and verifies a password.
Usage:
Example:
# Verify a password using the v1 private key and the encrypted data from a file
encrypt-file
Encrypts a single file.
Usage:
Example:
# Encrypt a file with the v1 public key
# Encrypt a file with a password as well
decrypt-file
Decrypts a single file.
Usage:
Example:
# Decrypt a file with the v1 private key
# Decrypt a file that was also encrypted with a password
encrypt-dir
Encrypts an entire directory by first archiving it into a .tar.gz.
Usage:
Example:
# Encrypt the "my_project" directory
decrypt-dir
Decrypts and extracts a directory.
Usage:
Example:
# Decrypt the "my_project.enc" file into the "decrypted_project" directory
rotate-key
Rotates encryption keys for a file or a directory of files.
Usage:
Example:
# Rotate keys from v1 to v2 for a single file
# Rotate keys from v1 to v2 for all files in the "encrypted_files" directory
As a Library (Crate)
You can also use ironcrypt as a library in your Rust projects. Add it to your Cargo.toml:
[]
= "0.1.0" # Replace with the desired version from crates.io
Encrypting and Verifying a Password
use ;
Encrypting and Decrypting a File
use ;
use fs;
Database Integration Examples
Here are some examples of how to use ironcrypt with popular web frameworks and a PostgreSQL database. These examples use the sqlx crate for database interaction.
Actix-web Example
This example shows how to create a simple web service with actix-web that can register and log in users.
Dependencies:
[]
= "0.1.0"
= "4"
= { = "0.7", = ["runtime-async-std-native-tls", "postgres"] }
= { = "1.0", = ["derive"] }
Code:
use ;
use PgPoolOptions;
use PgPool;
use ;
use Deserialize;
async
async
async
Rocket Example
This example shows how to achieve the same functionality using the rocket framework.
Dependencies:
[]
= "0.1.0"
= { = "0.5.0-rc.2", = ["json"] }
= { = "0.7", = ["runtime-tokio-native-tls", "postgres"] }
= { = "1.0", = ["derive"] }
Code:
extern crate rocket;
use Json;
use State;
use PgPoolOptions;
use PgPool;
use ;
use Deserialize;
async
async
async
Configuration
IronCrypt can be configured in three ways, in order of precedence:
ironcrypt.tomlfile: Create this file in the directory where you run the command.- Environment Variables: Set variables like
IRONCRYPT_KEY_DIRECTORY. - Command-Line Arguments: Flags like
--key-directoryoverride all other methods.
For library usage, you can construct an IronCryptConfig struct and pass it to IronCrypt::new.
Security and Best Practices
- Protect Your Private Keys: Never expose your private keys. Store them in a secure, non-public location.
- Use Strong Passwords: When using the password feature for file/directory encryption, ensure the password is strong.
- Rotate Keys Regularly: Use the
rotate-keycommand to update your encryption keys periodically. - Backup Your Keys: Keep secure backups of your keys. If you lose a private key, you will not be able to decrypt your data.
Contribution
Contributions are welcome! If you'd like to contribute, please follow these steps:
- Fork the repository on GitHub.
- Create a new branch for your feature or bug fix.
- Commit your changes and push them to your fork.
- Submit a pull request with a clear description of your changes.
License
IronCrypt is licensed under the MIT License. See the LICENSE file for details.