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:

sh
brew install gnupg

Install GnuPG on Ubuntu:

sh
sudo apt-get install gnupg

Test installation:

sh
gpg --version # example output gpg (GnuPG) 2.4.3 libgcrypt 1.10.2 Copyright (C) 2023 g10 Code GmbH ....

Encrypt a file:

sh
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:

sh
gpg --output decrypted_file.txt -d encrypted_file.gpg

Verify the files by generating a checksum:

sh
shasum -a 512 file_to_be_encrypted.txt shasum -a 512 decrypted_file.zip # they should be the same