Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@codemedic
Last active January 15, 2020 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codemedic/f459887960ea3a4eacdbd2958d4767be to your computer and use it in GitHub Desktop.
Save codemedic/f459887960ea3a4eacdbd2958d4767be to your computer and use it in GitHub Desktop.
GPG Key Backup

Run pdflatex --shell-escape gpgbackup.tex to produce a pdf that you can print and lock away.

In order to recover the key, you will have to scan extract individual QR Codes with names IMGa.png, IMGb.png, IMGc.png and IMGd.png, as given in the name of each figure, then run the recovery commands.

NOTE: The above command WILL leave some artefacts in /tmp which should be removed using the command rm /tmp/IMG*png

PS: Original formula for this gist was from @costrouc.

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{caption,subcaption}
\usepackage{float}
\usepackage{graphicx}
\usepackage{pgffor}
\def\gpgkey{YourKeyName}
\newcommand\gpgtopng{
\immediate\write18{gpg --export-secret-key \gpgkey | paperkey --output-type raw | base64 > temp}
\immediate\write18{split temp -n 4 IMG}
\immediate\write18{for f in IMG*; do cat $f | qrencode -o /tmp/$f.png; done}
\immediate\write18{rm IMG* temp}
}
\gpgtopng
\begin{document}
\centering
\begin{figure}
\foreach \i in {a, ..., d} {%
\centering
\begin{subfigure}[p]{0.45\textwidth}
\includegraphics[width=\linewidth]{/tmp/IMGa\i.png}
\caption{ }\label{fig:subfig\i}
\end{subfigure}\quad
}
\end{figure}
To recover run the following command
\begin{verbatim}
for f in IMG*.png; do zbarimg --raw $f | head -c -1 > $f.out ; done
cat *.out | base64 -d | paperkey --pubring ~/.gnupg/pubring.gpg | gpg --import
\end{verbatim}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment