Open flyinggreenfrog opened 4 years ago
Hi, I've never done this before but... out of curiosity I had a crack.
TLDR; (compare for yourself, not sure about the packet tag)
alias hexdump="hexdump -ve '1/1 \"%02x\n\" ' "
hexdump public.key.gpg > a ; hexdump private.key.gpg > b ; diff a b
It may not be immediately clear, but you can find your fingerprint in the data.
(From gpg -K --fingerprint
).
If you compare the diff with your paperkey, you will notice it follows the format as stated...:
a) Version of paperkey
b) OpenPGP key version
c) Key fingerprint (N octets)
d) 16-bit endian length of secret data (2 octets)
e) secret data
The diff is almost identical, except the first few differences you will notice are the "packet tag" which the OpenPGP implementation uses as a header, identifying whether the file is a public key, private key, encrypted data, etc; and how long the PGP packet is.
Following that is secret data, verbatim from diff to paper key it is identical. Just make sure you take into account (d) which is how long each packet goes for. The pattern repeats from b) - e) for each of your subkeys.
The thing that caught me out is I'm not sure exactly about how to switch out the packet tag, and what the differences are between old and new versions of the format. So how to do this manually is not yet confirmed for me.
Check out https://tools.ietf.org/html/rfc4880 for very detailed information about the format itself.
These might be helpful:
Out of curiosity I wanted to test the manual restore of a secret key without the paperkey program. From the paperkey backup explanation:
But how to really do that? In which format has the existing public key packet to be, so that I can edit it by hand and add the secret key data?