Encrypt and Decrypt Files on MacOS and Linux
Prerequisites: GnuPG - a complete and free implementation of the OpenPGP standard (https://gnupg.org/)
Install GnuPG on MacOS:
brew install gnupg
Install GnuPG on Ubuntu:
sudo apt-get install gnupg
Test installation:
gpg --version
# example output
gpg (GnuPG) 2.4.3
libgcrypt 1.10.2
Copyright (C) 2023 g10 Code GmbH
....
Encrypt a file:
gpg --output encrypted_file.gpg -c file_to_be_encrypted.txt
You will be prompted to enter a passphrase. Note that the passphrase should be at least 8 characters long and should contain at least 1 digit or special character.
Decrypt a file:
gpg --output decrypted_file.txt -d encrypted_file.gpg
Verify the files by generating a checksum:
shasum -a 512 file_to_be_encrypted.txt
shasum -a 512 decrypted_file.zip
# they should be the same