GPG (GNU Privacy Guard) keys are used to encrypt/decrypt text messages. The GPG public key is used to encrypt the message, whilst the GPG private key is used to decrypt the message.
When DM/PMing me, send me your GPG public key so I can send an encrypted message back to you and you can use the my GPG public key to encrypt messages to me.
NEVER NEVER NEVER send out your GPG private key! This key is for you and YOU only. If ANYONE asks for your private key, THEY ARE SCAMMING YOU OR TRYING TO STEAL YOUR DATA! Always back it up in a SECURE location like a raspberry pi NAS. Don't back it up on an untrustworthy server. If you lose your private key, YOUR MESSAGES ARE GONE FOREVER!
To encrypt a GPG message, use this command:
echo "message" | gpg --recipient "target" --recipient "your_key" --encrypt --armor -o - -
Replace message
with the message to encrypt
Replace target
with the recipient key ID
Replace your_key
with your GPG key ID
While you don't have to specify your key when encrypting, it makes it so you can't read your own sent messages. It does come at the downside of making messages slightly bigger as a result of including your key ID. You can also add as many "--recipient" options as you want.
To decrypt a GPG message, use this command:
echo "Encrypted text here" | gpg --decrypt
or
gpg --output unencrypted.txt --decrypt encrypted.gpg
To export your public key in binary, use this command:
gpg --export "key_id" --output gpg-pubkey.gpg
To export your public key in ASCII, use this command:
gpg --armor --export "key_id" --output gpg-pubkey-armor.txt