# Given a PGP public key, how can I extract its PGP fingerprint in hex, using v12.0?

This is related to the question "After using GenerateAsymmetricKeyPair [], how to print the two keys in hex?" which @Sjoerd Smit kindly answered.

How can I use Mathematica v12.0 to extract the PGP fingerprint from a PGP public key, in 40 hex characters as it usually rendered?

I would like to be able to do this from other people's public keys as well as from public keys (or for that matter private keys, which have the same fingerprint) that I have generated a moment before using GenerateAsymmetricKeyPair[].

As far as I can find from a quick Google (but correct me if I'm wrong), the PGP fingerprint is the SHA-1 hash of the key. You can calculated it with:

pair = GenerateAsymmetricKeyPair[]
ToUpperCase @ IntegerString[
Hash[
pair["PublicKey"]["PublicByteArray"],
"SHA"
],
16,
40
]


On a different note, you can check what's inside the key by using:

List @@ pair["PublicKey"]


It doesn't look like the fingerprint is generated by GenerateAsymmetricKeyPair itself.