pouriya / encdec

Simple RSA (Enc|Dec)rypt terminal utility with multipart & compression support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EncDec

A terminal encryption utility that supports multipart and compression.

Installation

Download the latest version:

Usage

Rename downloaded asset to encdec (encdec.exe on windows)

mv <DOWNLOADED_FILE> encdec

Make it executable

chmod a+x encdec

Test

./encdec --help
A terminal encryption utility that supports multipart and compression.

Usage: encdec <COMMAND>

Commands:
  gen   Generates private & public PEM files
  enc   Encryption
  dec   Decryption
  help  Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

Generate key pairs

Usage

./encdec gen --help
Generates private & public PEM files

Usage: encdec gen [OPTIONS] --name <NAME>

Options:
  -o, --output-directory <OUTPUT_DIRECTORY>
          Output directory to save keys [default: /p/encdec]
  -n, --name <NAME>
          Name of the generated keys that transforms to <NAME>.PRIV.pem and <NAME>.PUB.pem
  -k, --key-size-in-bytes <KEY_SIZE_IN_BYTES>
          Private key modulus key size in bytes [default: 256] [possible values: 128, 256, 512]
  -h, --help
          Print help

Example

./encdec gen -n test
Attempt to generate RSA private key with bit size 2048.
Generated private key
Attempt to generate RSA public key
Generated public key
Saved private PEM contents in "/p/encdec/test.PRIV.pem"
Saved private PEM contents in "/p/encdec/test.PUB.pem"
ls test*
test.PRIV.pem  test.PUB.pem
head -n 3 test.PRIV.pem # read first 3 lines
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAsxUmO3BcU0aM6uaP5ctNq4FtdbC+qX7cWfaL727Mt5N+uoLP
OXL2h65i9s67Dn0ZQNiROIYVcYSYPSxHoNhng9g60w5oesujZvGFvJGIwI5MfVGg
head -n 3 test.PUB.pem
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAsxUmO3BcU0aM6uaP5ctNq4FtdbC+qX7cWfaL727Mt5N+uoLPOXL2
h65i9s67Dn0ZQNiROIYVcYSYPSxHoNhng9g60w5oesujZvGFvJGIwI5MfVGgnCes

Encryption

Usage

./encdec enc --help
Encryption

Usage: encdec enc [OPTIONS] --public-pem-file <PUBLIC_PEM_FILE> --input-filename <INPUT_FILENAME> --output-filename <OUTPUT_FILENAME>

Options:
  -p, --public-pem-file <PUBLIC_PEM_FILE>
          Public key PEM file
  -i, --input-filename <INPUT_FILENAME>
          Input file to encrypt
  -o, --output-filename <OUTPUT_FILENAME>
          Output file to save encrypted contents
  -z, --zip
          If input is too large, encrypts input part by part and stores them inside a .zip file
  -h, --help
          Print help

Example

cat secret.txt # We are going to encrypt this sample
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tellus elit, tristique vitae mattis egestas, ultricies vitae risus. Quisque sit amet quam ut urna aliquet
molestie. Proin blandit ornare dui, a tempor nisl accumsan in. Praesent a consequat felis. Morbi metus diam, auctor in auctor vel, feugiat id odio. Curabitur ex ex,
dictum quis auctor quis, suscipit id lorem. Aliquam vestibulum dolor nec enim vehicula, porta tristique augue tincidunt. Vivamus ut gravida est. Sed pellentesque, dolor
vitae tristique consectetur, neque lectus pulvinar dui, sed feugiat purus diam id lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
inceptos himenaeos. Maecenas feugiat velit in ex ultrices scelerisque id id neque.
./encdec enc -p test.PUB.pem -i secret.txt -o encrypted
Attempt to check for PKCS#1 method
Updated chunk size to 128
Saved encrypted output to "encrypted.zip"
unzip -l encrypted.zip # List files inside .zip file
Archive:  encrypted.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2024-04-09 21:45   parts/
      256  2024-04-09 21:45   parts/encrypted.1
      256  2024-04-09 21:45   parts/encrypted.2
      256  2024-04-09 21:45   parts/encrypted.3
      256  2024-04-09 21:45   parts/encrypted.4
      256  2024-04-09 21:45   parts/encrypted.5
      256  2024-04-09 21:45   parts/encrypted.6
---------                     -------
     1536                     7 files

Decryption

Usage

./encdec dec --help
Decryption

Usage: encdec dec --private-pem-file <PRIVATE_PEM_FILE> --input-filename <INPUT_FILENAME> --output-filename <OUTPUT_FILENAME>

Options:
  -p, --private-pem-file <PRIVATE_PEM_FILE>  Private key PEM file
  -i, --input-filename <INPUT_FILENAME>      Input file to decrypt
  -o, --output-filename <OUTPUT_FILENAME>    Output file to save decrypted contents
  -h, --help                                 Print help

Example

./encdec dec -p test.PRIV.pem -i encrypted.zip -o decrypted-secret.txt
Attempt to check for PKCS#1 method
Saved decrypted output to "decrypted-secret.txt"
cat decrypted-secret.txt
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tellus elit, tristique vitae mattis egestas, ultricies vitae risus. Quisque sit amet quam ut urna aliquet
molestie. Proin blandit ornare dui, a tempor nisl accumsan in. Praesent a consequat felis. Morbi metus diam, auctor in auctor vel, feugiat id odio. Curabitur ex ex,
dictum quis auctor quis, suscipit id lorem. Aliquam vestibulum dolor nec enim vehicula, porta tristique augue tincidunt. Vivamus ut gravida est. Sed pellentesque, dolor
vitae tristique consectetur, neque lectus pulvinar dui, sed feugiat purus diam id lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
inceptos himenaeos. Maecenas feugiat velit in ex ultrices scelerisque id id neque.
md5sum secret.txt decrypted-secret.txt 
e17df2471b7b1037c63ca60723f56457  secret.txt
e17df2471b7b1037c63ca60723f56457  decrypted-secret.txt

To contributors

I ❤️ PR from everyone and I appreciate your help but before opening a PR, file an issue and describe your feature, bug, etc.

About

Simple RSA (Enc|Dec)rypt terminal utility with multipart & compression support

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Rust 89.6%Language:Makefile 5.8%Language:Shell 4.5%