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:
- OpenPGP.js is really cool and easy to use, get it a look
- to avoid depending from native PHP extentions I've used this
composer install
able library, which is unfortunately mostly undocumented
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;
}