Extracting the PGP keyid from the public key file
Is there a way via an CLI tool or some kind of API to extract the PGP key ID from the PGP public key block?
I found the hexa value of the key in the binary file, but I guess the position is based on the key kind/size.
Basically, I have the base64 formatted public key and I would like to retrieve the key ID from it, without importing it with GnuPG.
RFC 4880 on OpenPGP message format talks about how to calculate key ID from public key.
Excerpts from section 12.2:
For a V3 key, the eight-octet Key ID consists of the low 64 bits of the public modulus of the RSA key.
And for V4 keys:
A V4 fingerprint is the 160-bit SHA-1 hash of the octet 0x99, followed by the two-octet packet length, followed by the entire Public-Key packet starting with the version field. The Key ID is the low-order 64 bits of the fingerprint.
You can easily parse the last 64 bits from the base64 encoded public keys, which is the key ID for the corresponding public key.