Skip to content

Lightweight Python CLI tool for encryption, decryption, signing, and verification using crypto algorithms.

Notifications You must be signed in to change notification settings

ayiman29/PRIVHAT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Privhat

    ____  ____  _____    __   __  _____  ______
   / __ \/ __ \/  _/ |  / /  / / / /   |/_  __/
  / /_/ / /_/ // / | | / /  / /_/ / /| | / /   
 / ____/ _, _// /  | |/ /  / __  / ___ |/ /    
/_/   /_/ |_/___/  |___/  /_/ /_/_/  |_/_/     
                                               

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.


πŸ–ΌοΈ Screenshot

Here’s a glimpse of PRIVHAT:

CLI Screenshot


Features

  • 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

Installation

  1. Clone this repository:
git clone https://github.com/ayiman29/privhat.git
cd privhat
  1. (Optional) Create and activate a Python virtual environment:
python -m venv venv
source venv/bin/activate   # Linux/macOS
venv\Scripts\activate      # Windows
  1. Install dependencies:
pip install -r requirements.txt

πŸ› οΈ Usage

Run the CLI tool using Python:

python privhat.py [command] [options]

πŸ“‹ Commands

πŸ‘€ Create User

Create a new user and generate a key pair:

python privhat.py create-user <username> --alg rsa|ecc|elgamal

❌ Delete User

Delete an existing user and their stored keys:

python privhat.py delete-user <username>

πŸ“₯ Import Public Key

Import an RSA public key manually:

python privhat.py import-pubkey <username> --e <int> --n <int>

πŸ“œ List Users

List all registered users and their key status (local or imported):

python privhat.py list-users

πŸ” Encrypt

python privhat.py encrypt [OPTIONS]

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

βœ… Encrypt Examples

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

πŸ”“ Decrypt

python privhat.py decrypt [OPTIONS]

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

βœ… Decrypt Examples

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...."

πŸ” Summary Matrix

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>

✍️ Sign

python privhat.py sign [OPTIONS]

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)

βœ… Sign Examples

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

βœ… Verify

python privhat.py verify [OPTIONS]

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)

βœ… Verify Examples

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

πŸ” Summary Matrix

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>

Directory Structure

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

Notes

  • Current implementation supports RSA fully; ECC and ElGamal are in progress.

About

Lightweight Python CLI tool for encryption, decryption, signing, and verification using crypto algorithms.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages