Skip to content

Instantly share code, notes, and snippets.

@jeremiehuchet
Last active February 12, 2020 14:28
Show Gist options
  • Select an option

  • Save jeremiehuchet/0c2dfe08a4afe2c33e4933947b96196d to your computer and use it in GitHub Desktop.

Select an option

Save jeremiehuchet/0c2dfe08a4afe2c33e4933947b96196d to your computer and use it in GitHub Desktop.
Backup GPG key
#!/bin/sh -e
if [[ $# -ne 1 ]] ; then
cat - <<HELP
usage: $0 <gpg secret key id>
Generates a printable PDF file <gpg secret key id>-backup.pdf for the given key id.
HELP
exit 1
fi
KEY_ID=$1
gpg --export-secret-keys $1 | paperkey > $KEY_ID.txt
enscript -p - $KEY_ID.txt | ps2pdf - > $KEY_ID.pdf
cat $KEY_ID.txt | split -b 1200 - $KEY_ID-part-
for part in $KEY_ID-part-*; do
qrencode -l H -r $part -o $part.png
convert $part.png -background white -alpha remove -alpha off $part-opaque.png
img2pdf -o $part.pdf $part-opaque.png
done
convert $KEY_ID.pdf $KEY_ID-part-*.pdf $KEY_ID-backup.pdf
rm $KEY_ID.*
rm $KEY_ID-part-*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment