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.
- 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.
- Generate a symmetric key to encrypt a file.
- Zip the file before encryption with the symmetric key.
- Encrypt the zipped file using the symmetric key.
- Encrypt the symmetric key with the RSA public key.
- Attach the encrypted symmetric key to the encrypted file.
- Split the encrypted symmetric key from the encrypted file (the bundle file).
- Decrypt the symmetric key using the RSA private key.
- Decrypt the encrypted file using the decrypted symmetric key.
- Unzip the decrypted file.
Ensure you have OpenSSL installed on your system. You can install it using:
sudo apt-get install openssl
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.
./encrypt.sh input_file output_file
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.
./decrypt.sh encrypted_file encrypted_key output_file
- Clone the repository:
git clone https://github.com/yourusername/minigpg.git
cd minigpg
- Make the scripts executable:
chmod +x encrypt.sh decrypt.sh
- Run the encryption script:
./encrypt.sh path/to/input_file
- Run the decryption script:
./decrypt.sh path/to/encrypted_file
This project is licensed under the MIT License. See the LICENSE file for details.