____ ____ _____ __ __ _____ ______
/ __ \/ __ \/ _/ | / / / / / / |/_ __/
/ /_/ / /_/ // / | | / / / /_/ / /| | / /
/ ____/ _, _// / | |/ / / __ / ___ |/ /
/_/ /_/ |_/___/ |___/ /_/ /_/_/ |_/_/
Privhat is a lightweight command-line cryptography tool written in Python that supports key user management, encryption, decryption, signing, and signature verification with multiple algorithms like RSA, ECC, and ElGamal. All cryptographic functions are self-implemented for educational purposes, providing hands-on insight into the underlying algorithms and processes.
Note: Privhat is a lightweight, educational tool with self-implemented cryptographic algorithms and is not intended for securing real-world sensitive data. It lacks the rigorous security audits and protections of established cryptographic libraries. For actual privacy and security needs, please rely on well-vetted tools created by experts so paranoid and skilled that the feds occasionally show up at their door β like OpenGPG or other widely trusted cryptographic software.
Hereβs a glimpse of PRIVHAT:
- Create and delete users with keypairs (RSA, ECC, ElGamal)
- Import public keys from JSON files or directly via parameters
- Encrypt messages/files using user public keys or direct keys
- Decrypt messages/files using private keys
- Sign messages and verify signatures (planned features)
- Clean CLI interface with intuitive commands
- Organized storage for keys, messages, and users
- Easily ignore sensitive ciphertext and plaintext files in
.gitignore
- Clone this repository:
git clone https://github.com/ayiman29/privhat.git
cd privhat
- (Optional) Create and activate a Python virtual environment:
python -m venv venv
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows
- Install dependencies:
pip install -r requirements.txt
Run the CLI tool using Python:
python privhat.py [command] [options]
Create a new user and generate a key pair:
python privhat.py create-user <username> --alg rsa|ecc|elgamal
Delete an existing user and their stored keys:
python privhat.py delete-user <username>
Import an RSA public key manually:
python privhat.py import-pubkey <username> --e <int> --n <int>
List all registered users and their key status (local or imported):
python privhat.py list-users
python privhat.py encrypt [OPTIONS]
Option | Description |
---|---|
--to <username> |
Encrypt using a registered user's public key |
--pubkey-file <path> |
Encrypt using a public key file (JSON) |
--text <string> |
Plaintext input to encrypt |
--in <file> |
Input plaintext file |
--out <file> |
Output ciphertext file |
--pubkey-e <value> --pubkey-n <value> |
Encrypt using raw RSA public key components |
--alg <rsa | ecc | elgamal> |
Algorithm to use |
1. Encrypt Text to a User (stored public key)
python privhat.py encrypt --to alice --text "Hello Alice" --out hello.enc --alg rsa
2. Encrypt a File to a User
python privhat.py encrypt --to alice --in notes.txt --out notes.enc --alg rsa
3. Encrypt Text with a Public Key File
python privhat.py encrypt --pubkey-file keys/bob_pubkey.json --text "Secret message" --out msg.enc --alg rsa
4. Encrypt File with a Public Key File
python privhat.py encrypt --pubkey-file keys/bob_pubkey.json --in doc.txt --out doc.enc --alg rsa
5. Encrypt Text and Output to Stdout
python privhat.py encrypt --to alice --text "Just display this" --alg rsa
6. Encrypt Text Using Raw Public Key Components
python privhat.py encrypt --pubkey-e 65537 --pubkey-n 123456789123456789123456789 --text "Hello from raw key" --out out.enc --alg rsa
python privhat.py decrypt [OPTIONS]
Option | Description |
---|---|
--user <username> |
Registered user to use for decryption |
--in <file> |
Encrypted file input |
--cipher <string> |
Encrypted ciphertext string (Base64 or hex) |
--out <file> |
Output plaintext file |
1. Decrypt File and Save Output
python privhat.py decrypt --user alice --in hello.enc --out hello.txt
2. Decrypt Ciphertext Hex String
python privhat.py decrypt --user iloveglass2 --cipher "12345...."
Use Case | Encrypt Command | Decrypt Command |
---|---|---|
Encrypt text to user | --to <user> --text <text> |
--user <user> --cipher <hex> |
Encrypt file to user | --to <user> --in <file> |
--user <user> --in <file> |
Encrypt text with key file | --pubkey-file <file> --text <text> |
N/A |
Encrypt file with key file | --pubkey-file <file> --in <file> |
N/A |
Decrypt file to stdout | N/A | --user <user> --in <file> |
Decrypt ciphertext string to stdout | N/A | --user <user> --cipher <hex> |
Decrypt ciphertext string to file | N/A | --user <user> --cipher <hex> --out <file> |
python privhat.py sign [OPTIONS]
Option | Description |
---|---|
--user <username> |
Username whose private key will be used to sign |
--in <file> |
File containing message to sign |
--text <string> |
Plaintext message to sign directly |
--out <file> |
Output file to save the signature (optional) |
--alg <rsa | ecdsa> |
Algorithm to use for signing (rsa or ecdsa ) |
1. Sign Text Message and Save Signature
python privhat.py sign --user alice --text "This is a signed message." --out sig.txt --alg rsa
2. Sign File and Save Signature
python privhat.py sign --user bob --in important.txt --out important.sig --alg rsa
3. Sign Text Message and Output to Stdout
python privhat.py sign --user alice --text "Ephemeral signature" --alg rsa
python privhat.py verify [OPTIONS]
Option | Description |
---|---|
--from <username> |
Username whose public key will be used for verification |
--in <file> |
Input file containing the original message |
--text <string> |
Message to verify directly as string |
--sig <file> |
Signature file path |
--cipher <string> |
Signature directly as string (e.g. from stdout) |
--alg <rsa | ecdsa> |
Algorithm used for signature (rsa or ecdsa ) |
1. Verify Text and Signature File
python privhat.py verify --from alice --text "This is a signed message." --sig sig.txt --alg rsa
2. Verify File and Signature File
python privhat.py verify --from bob --in important.txt --sig important.sig --alg rsa
3. Verify Text and Signature String
python privhat.py verify --from alice --text "Hello world" --cipher "abc123def456..." --alg rsa
4. Verify File with Inline Signature String
python privhat.py verify --from bob --in statement.txt --cipher "abcd1234..." --alg rsa
Use Case | Sign Command | Verify Command |
---|---|---|
Sign text to stdout | --text <string> |
N/A |
Sign text and save to file | --text <string> --out <file> |
--text <string> --sig <file> or --cipher <string> |
Sign file and save to file | --in <file> --out <file> |
--in <file> --sig <file> or --cipher <string> |
Verify text with signature | N/A | --text <string> --sig <file> or --cipher <string> |
Verify file with signature | N/A | --in <file> --sig <file> or --cipher <string> |
privhat/
β
βββ privhat.py # Main CLI entry point
βββ crypto_engine.py # Core crypto operations
βββ user_manager.py # User and key management
βββ storage/
β βββ users.json # Registered users
β βββ keys/ # Private/public keys
β βββ messages/ # Ciphertext/plaintext files (add to .gitignore)
βββ requirements.txt
βββ README.md
- Current implementation supports RSA fully; ECC and ElGamal are in progress.