How the Fingerprint and Long and Short Key IDs are Related
Each OpenPGP key has a fingerprint attached, calculated mainly from its public key packet which also contains the creation time. The calculation is defined in RFC 4880, OpenPGP, 12.2. Key IDs and Fingerprints.
There are short and long key IDs, which resemble the lower 32 respective 64 bits of the fingerprint. For example, looking at the IDs of my OpenPGP key:
fingerprint: 0D69 E11F 12BD BA07 7B37 26AB 4E1F 799A A4FF 2279
long id: 4E1F 799A A4FF 2279
short id: A4FF 2279
Fingerprints and key IDs are used, as sharing and comparing a whole key with usually 1024 to 8096 bits (adding some more for headers like the creation date) is very impractical.
Using Long Key IDs
Whenever specifying OpenPGP keys, you can not only pass short key IDs, but also long key IDs and even whole fingerprints. Instead of passing the short key ID
gpg --recv-keys A4FF2279
you can always write the long key ID
gpg --recv-keys 4E1F799AA4FF2279
or even the full fingerprint (recommended for scripting and similar purpose)
gpg --recv-keys 0D69E11F12BDBA077B3726AB4E1F799AA4FF2279
Printing Long Key IDs
But where to take the long key ID from? If anybody passed his short ID, you cannot do anything but trying to fetch all keys for that ID, and see if there is a collision (and hope nobody is hiding the real key from you, and only passing the faked one).
So whenever handing over your OpenPGP key ID, announce the long ID! You can easily make GnuPG printing this one by adding the --keyid-format long
option:
gpg --keyid-format long --list-keys email@jenserat.de
This option takes values short
or 0xshort
for short key IDs (without or with 0x
prefixed to indicate that it is a hex number) and long
or 0xlong
for long key IDs.
Configurating Long Key IDs as Default
To make sure GnuPG is always printing the long key ID, add the option to your ~/.gnupg/gpg.conf
file stripping the --
. For example, I have configured GnuPG to always print the 0x
-prefixed long key ID by adding a line
keyid-format 0xlong
Printing the Fingerprint
Sadly, you cannot set GnuPG to print the whole fingerprint this way, probably because it would break GnuPG's output format for pretty much every screen size. Instead, request it by running
gpg --fingerprint 4E1F799AA4FF2279
which will dump something like
pub 8192R/0x4E1F799AA4FF2279 2012-12-25
Key fingerprint = 0D69 E11F 12BD BA07 7B37 26AB 4E1F 799A A4FF 2279
As this has the disadvantage of containing spaces (bad thing for using it in scripting), you could use the colon-delimited machine-readable output instead:
gpg --with-colons --fingerprint 4E1F799AA4FF2279
To filter everything but the fingerprint, additionally use grep
and cut
:
gpg --with-colons --fingerprint 4E1F799AA4FF2279 | grep fpr | cut -d ':' -f 10