Skip to content

Instantly share code, notes, and snippets.

@mugdha-adhav
Last active October 24, 2023 17:01
Show Gist options
  • Save mugdha-adhav/bfff6c101564dd2f98ef58d3e0ed5e08 to your computer and use it in GitHub Desktop.
Save mugdha-adhav/bfff6c101564dd2f98ef58d3e0ed5e08 to your computer and use it in GitHub Desktop.
PGP encryption and decryption

GPG encryption

Exporting keys directly -

Note: Using this method you may import both the public and private key using just the private key

Export private key

gpg --armor --export-secret-keys --output foo.asc bar@gmail.com

Import public & private key

gpg --import foo.asc

Exporting keys using paper key -

Note: Using this method you have to import both the public and private keys

Export public key

gpg --output public-key.pgp --armor --export bar@gmail.com

Encode the secret key as QR Code

gpg --export-secret-key key-id | paperkey --output-type raw | qrencode --8bit --output secret-key.qr.png

Restore the secret key from QR code

gpg --dearmor public-key.pgp
zbarimg -1 --raw -q -Sbinary secret-key.qr.png | paperkey --pubring public-key.pgp.gpg | gpg --import

Reference: https://wiki.archlinux.org/title/Paperkey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment