Skip to content

barrychum/miniGPG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MiniGPG: Simple GPG-like Encryption with OpenSSL

GPG (GNU Privacy Guard) encryption is a cryptographic tool used for secure communication and data encryption. It implements the OpenPGP standard for encrypting and signing data and communications. GPG uses a combination of symmetric-key cryptography for speed and public-key cryptography for secure key exchange. Users create a pair of keys: a public key, which is shared, and a private key, which is kept secret. Data encrypted with the public key can only be decrypted with the corresponding private key, ensuring confidentiality and authenticity.

MiniGPG is a simplified implementation inspired by GPG encryption, designed for educational purposes. It leverages OpenSSL to perform cryptographic operations and provides an easy-to-understand framework for learning about encryption and decryption processes. While MiniGPG can effectively demonstrate these principles, it may require additional development and security enhancements for use in production environments.

Preparation Process:

  1. Create a public-private RSA key pair.

Generate Private Key:

openssl genpkey -algorithm RSA -out encryption.key -aes256 -pass pass:your_password
or
openssl genpkey -algorithm RSA -out encryption.key

Generate Public Key:

openssl rsa -pubout -in encryption.key -out encryption.pub -passin pass:your_password
or
openssl rsa -pubout -in encryption.key -out encryption.pub

Put the private key and the public key in ~/.ssh folder.
Make sure the private key is only accessible by you, and it is backed up properly.

Encryption Process:

  1. Generate a symmetric key to encrypt a file.
  2. Zip the file before encryption with the symmetric key.
  3. Encrypt the zipped file using the symmetric key.
  4. Encrypt the symmetric key with the RSA public key.
  5. Attach the encrypted symmetric key to the encrypted file.

Decryption Process:

  1. Split the encrypted symmetric key from the encrypted file (the bundle file).
  2. Decrypt the symmetric key using the RSA private key.
  3. Decrypt the encrypted file using the decrypted symmetric key.
  4. Unzip the decrypted file.

Prerequisites

Ensure you have OpenSSL installed on your system. You can install it using:

sudo apt-get install openssl

Scripts

1. encrypt.sh

This script performs the following steps:

  • Creates an RSA public-private key pair (if not already created).
  • Generates a symmetric key.
  • Zips the given file.
  • Encrypts the zipped file using the symmetric key.
  • Encrypts the symmetric key with the RSA public key.
  • Outputs the encrypted file and the encrypted symmetric key.

alt text

Usage

./encrypt.sh input_file output_file

2. decrypt.sh

This script performs the following steps:

  • Splits the encrypted symmetric key from the encrypted file (the bundle file).
  • Decrypts the symmetric key using the RSA private key.
  • Decrypts the encrypted file using the decrypted symmetric key.
  • Unzips the decrypted file.

alt text

Usage

./decrypt.sh encrypted_file encrypted_key output_file

How to Use

  1. Clone the repository:
git clone https://github.com/yourusername/minigpg.git
cd minigpg
  1. Make the scripts executable:
chmod +x encrypt.sh decrypt.sh
  1. Run the encryption script:
./encrypt.sh path/to/input_file 
  1. Run the decryption script:
./decrypt.sh path/to/encrypted_file 

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A mini project to replicate GPG encryption

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages