November 06, 2013

GPG Hints

Symmetric encryption

Encrypting a file with AES256

$ gpg -c -a --cipher-algo AES256 --no-use-agent -o mydata.gpg mydata.txt

Notes

-c - encrypt with a symmetric cipher using a passphrase

-a (–armor) - the output will be base64 encoded

To see all cipher algorithms, run ‘gpg –version’

Decrypting the file

$ gpg --no-use-agent -o mydata.txt -d mydata.gpg

GPG Key management

To create a key

gpg --gen-key

To export a public key into file publickey.asc

gpg --export -a "User Name" > publickey.asc

To export a private key

gpg --export-secret-key -a "User Name" > privatekey.asc

To import a public key

gpg --import publickey.asc

To import a private key

gpg --allow-secret-key-import --import privatekey.asc

To trust the key

gpg --edit-key KEYNAME
trust
quit

Exporting a GPG Key Using the Command Line

gpg --keyserver hkp://subkeys.pgp.net --send-key KEYNAME

For //KEYNAME//, substitute the key ID of your primary keypair.

To list the keys in your public key ring

gpg --list-keys

To list the keys in your secret key ring:

gpg --list-secret-keys

To encrypt data, use:

gpg -e -u "Sender User Name" -r "Receiver User Name" somefile

To decrypt data, use:

gpg -o decryptedfile -d encryptedfile.gpg

Find and import GPG Public Key based on name or email. Useful when you don’t know or forgot ID of the key.

gpg --keyserver hkp://subkeys.pgp.net --search-keys NAMEorEMAILpattern
gpg --keyserver hkp://subkeys.pgp.net --recv-key 0x9F600825

http://blog.tremily.us/posts/GnuPG_maintenance/

References

I used as a source Charles Lockhart’s GPG Cheat Sheet

See also