GPG Encryption & Decryption Guide (Mac CLI)
Purpose
This document outlines the secure procedure for encrypting and decrypting files using GNU Privacy Guard (GPG) public/private key pairs on macOS. It is intended for scenarios where sensitive files (e.g., source code, credentials) must be transferred securely so that only the intended receiver can decrypt them.1. Installation
Install GPG on macOS via Homebrew:2. Roles in the Process
- Receiver: The individual or entity that will decrypt the file. They must generate and securely store their GPG private key.
- Sender: The individual encrypting the file. They use the receiver’s public key to encrypt the content.
3. Process Overview
- Receiver generates GPG keypair
- Receiver exports and shares public key
- Sender imports receiver’s public key
- Sender zips the files to be sent
- Sender encrypts the zip using receiver’s public key
- Sender shares the encrypted file
- Receiver decrypts the file using private key
- Receiver extracts the original files
4. Step-by-Step Guide
Step 1: Generate GPG Keypair (Receiver only)
- Name
- Email address
- Passphrase (must be strong and kept secure)
- Share
receiver-public-key.ascwith the sender via a secure channel. - Never share your private key.
Step 2: Import Receiver’s Public Key (Sender only)
Step 3: Create the ZIP File (Sender only)
Step 4: Encrypt the ZIP File (Sender only)
Basic binary encryption:Step 5: Share the Encrypted File
Sendsecret.zip.gpg or secret.zip.asc to the receiver via:
- Secure file transfer (SFTP, corporate portal)
- Encrypted email Do not send over insecure channels like public chat.
Step 6: Decrypt the File (Receiver only)
Binary format:Step 7: Extract the Files (Receiver only)
5. Quick Reference Commands
| Action | Command |
|---|---|
| Export public key | gpg --armor --export "email" > public-key.asc |
| Import public key | gpg --import public-key.asc |
| Encrypt | gpg -e -r "email" file.zip |
| Decrypt | gpg -o file.zip -d file.zip.gpg |
6. Security Best Practices
- Always verify the public key’s fingerprint with the receiver before encrypting.
- Store private keys in a secure, access-controlled environment.
- Use strong passphrases for private keys and never share them.
- Keep an audit log of who received encrypted files and when.
- If possible, use Out-of-Band verification for key exchange.
