A minimal RSA implementation in Rust for generating keys, encrypting files, and decrypting them using command-line interface. Ideal for educational purposes, learning cryptographic concepts, or lightweight encryption tasks.
- Generate RSA key pairs using random two-digit primes
- Save and load public/private keys in readable format
- Encrypt and decrypt binary files using RSA
- Modular CLI interface with
clap - Educational and compact implementation
- Clone the repository:
git clone https://github.com/martian58/mini_rsa.git
cd mini-rsa- Build the project:
cargo build --release- Run the CLI:
./target/release/mini_rsa --helpOr use the prcompiled binaries
mini_rsa-win_v1.0.exe
mini_rsa_v1.0-x86_64-linux ./mini_rsa generate --name mykeyGenerates:
mykey.pub: Public keymykey: Private key
./mini_rsa encrypt --input secret.txt --output secret.enc --key mykey.pub
secret.txt→secret.enc
./mini_rsa decrypt --input secret.enc --output revealed.txt --key mykey
secret.enc→revealed.txt
- Picks two random two-digit prime numbers.
- Calculates RSA parameters:
n,phi,e, and privated. - Uses modular exponentiation for both encryption and decryption.
- Keys are saved in a simple custom format for easy inspection.
$ ./mini_rsa generate --name demo
Keys generated: demo.pub (public), demo (private)
$ ./mini_rsa encrypt -i hello.txt -o hello.enc -k demo.pub
File encrypted: hello.enc
$ ./mini_rsa decrypt -i hello.enc -o hello_out.txt -k demo
File decrypted: hello_out.txtExample demo.pub:
-----BEGIN RSA PUBLIC KEY-----
65537 3233
-----END RSA PUBLIC KEY-----
This implementation is for educational purposes only and not secure for real-world cryptographic use. It uses small key sizes and lacks padding schemes.