Key of the Key

Recently I've worked a little with GPG keys in a web application (mostly to digitally sign documents, with PIN-protected keys).

Two considerations:

An hint for future explorers: to retrieve the key ID of a given public key, use this function (built mining for references in GitHub):

/*
    $pubkey is meant to be the contents of the armored file
*/
function get_key_id($pubkey) {
    $data = \OpenPGP::unarmor($pubkey, 'PGP PUBLIC KEY BLOCK');
    $key = \OpenPGP_Message::parse($data);
    foreach ($key as $p) {
        if ($p instanceof \OpenPGP_PublicKeyPacket) {
            return $p->key_id;
        }
    }

    return null;
}