Skip to content

Instantly share code, notes, and snippets.

@elquimista
Forked from joostrijneveld/gpg2qrcodes.sh
Last active January 17, 2024 16:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elquimista/bc9b6e0bfb41e8da7edbfeec8c9b2045 to your computer and use it in GitHub Desktop.
Save elquimista/bc9b6e0bfb41e8da7edbfeec8c9b2045 to your computer and use it in GitHub Desktop.
Produce printable QR codes for persistent, tangible storage of GPG private keys and vice versa.
# Depends on:
# paperkey (jabberwocky.com/software/paperkey/)
# libqrencode (fukuchi.org/works/qrencode/)
# Producing the QR codes:
# Split into 16 codes to ensure the data per image is not too large.
# Or split into 3 codes for smaller keys (e.g., ed25519)
gpg --export-secret-key KEYIDGOESHERE | paperkey --output-type raw | base64 > temp
if [ "$(uname)" == "Darwin" ]; then
split -n 16 temp IMG
else
split temp -n 16 IMG
fi
for f in IMG*; do cat $f | qrencode -o $f.png; done
# Depends on:
# paperkey (jabberwocky.com/software/paperkey/)
# zbar (zbar.sourceforge.net)
# Importing the QR codes:
# Note that, when making scans or photographs, do not produce large images.
# If zbar fails to recognise your QR code, try downscaling the image.
if [ "$(uname)" == "Darwin" ]; then
for f in IMG*.png; do zbarimg --raw $f | head > $f.out ; done
else
for f in IMG*.png; do zbarimg --raw $f | head -c -1 > $f.out ; done
fi
gpg --export KEYIDGOESHERE > pubkey.gpg
cat *.out | base64 --decode | paperkey --pubring pubkey.gpg > key.gpg
gpg --import key.gpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment