I would love to use Bob and Alice for this article, unfortunately Bob’s name is too short. It needs a minimum length of 5 characters. To install GnuPG run
# macOS
brew install gnupg
# Ubuntu
sudo apt install gnupg
First you’ll need to generate the key.
gpg --gen-key
Enter your passphrase
And then reenter the same passphrase
Key generated successfully
To check if your keys are generated successfully
gpg --list-keys
Generate a ASCII armored version of the public key.
gpg --output kevin_public.key --export --armor kevin
Now that you have the public key. You can distribute this public key to anyone that wish to send you an encrypted file. The person that received your public key needs to import it into their key list.
gpg --import kevin_public.key
To list all the public keys
gpg --list-public-keys
To trust the public key
gpg --edit-key kevin
To encrypt
# --encrypt = to encrypt the file
# --armor = output encrypted file as ASCII
# --recipient = the imported public key uid
gpg --encrypt --armor --recipient kevin plain.txt
# or
gpg -e -a -r kevin plain.txt
# or
gpg -ear kevin plain.txt
By default the encrypted file output is a binary file
You need to have a secret/private key to sign the encrypted file
gpg --list-secret-keys
To sign and encrypt
gpg --encrypt --armor --sign --recipient kevin plain.txt
# or
gpg -easr kevin plain.txt
To decrypt
gpg --decrypt plain.txt.asc
To delete key from the list of keys. First list all the keys
gpg --list-keys
To delete key “alice”
gpg --delete-key alice