How to encrypt a file with symmetric encryption
Privacy Windows Linux macOS Desktop PGP
Sidst opdateret:
In this guide, you'll learn how to encrypt a file using symmetric encryption. If you want to learn more about encryption, read our guide The basics of encryption.
1. Install GnuPG
First, you need to install GnuPG on your operating system. GnuPG, or GPG as it's often called, is a free software program based upon the PGP encryption standard that allows users to encrypt and sign data, and even to manage keys.
- Linux: Open a terminal window and run the command
sudo apt-get install gnupg2
- Windows: Download GnuPG from the GNU Privacy Guard for Windows website and install it.
- macOS: Open a terminal window and run the command
brew install gpg
(if the command doesn't work, you probably need to first install Homebrew).
2. Encrypt your file
Open a terminal window to run the following command. Replace "filename.txt" with the full name of the file you want to encrypt. You will be prompted to use a password.
- Windows:
gpg -c -a --cipher-algo AES256 filename.txt
- macOS, Linux:
gpg2 -c -a --cipher-algo AES256 filename.txt
3. Decrypt your file
The following command will decrypt the file. Remember to replace "filename" with the name of your encrypted file.
- Windows:
gpg -d -a filename.txt.asc
- macOS, Linux:
gpg2 -d -a filename.txt.gpg
Note: the file extension can be either .asc or .gpg. The file's content will display in the terminal.
To output the content to a file add the --output flag
- macOS, Linux:
gpg2 -d -a --output decryptedfilename filename.txt.gpg