I've seen key IDs used in several places and would like to use them in my program, but I haven't been able to find a description of them. How are they generated?
相关问题
- C# Rijndael decryption returns extra question mark
- java 11 HttpClient leads to endless SSL loop even
- AesManaged and RijndaelManaged
- Is It Ever Recommended To Use The ECB Cipher Mode?
- How to implement IDEA?
相关文章
- Working with hmacsha256 in windows store app
- Decrypting EnvelopedCms with non-default Algorithm
- How to get the size of a RSA key in Java
- Sanity check SSH public key? [closed]
- Use RSA with Eclipse Remote Systems Explorer?
- How to apply padding for Base64
- How to switch from AES-256 to AES-128?
- Encrypting with PHP; decrypting with CryptoJS
In the case of the Strongswan one can display what it refers to as the
keyid
using its command line utilities. The main point of thekeyid
is that it can be used to identify the actual public key contained within a certificate so that a certificate might change but by checking the keyid one can check whether the key has changed or not.The
pki
command will list the keyids of an X.509 cert as follows (where thesubjectPublicKeyInfo hash
is thekeyid
):Or for an RSA private key:
The second command is
ipsec
which one can use to list all the certs (and config) installed in the/etc/ipsec.d
subdirectories (this command will list the certificates and their correspondingkeyid
which is the same as theirsubjectPublicKeyInfo hash
listed by thepki
command):Also one can use
openssl
to generate Strongswan's idea of akeyid
, which is basically the SHA1 of the actual RSA public key (thesed
script just strips the '-----BEGIN PUBLIC KEY-----' and END banners) [Corrected after Micah's comment]:In different formats (PGP, SSH, X.509 certificates) key ID has different meaning. Neither SSH nor X.509 have a "dedicated" concept of key ID, but some people use this term (including their software) - in this case it's usually a hash of the public key or of the certificate in whole.
Update: the comments reminded me that "key identifier" extensions exist in X.509 certifiactes, and they sometimes are being referred to as key IDs. Yet, this is not common - usually the hash (also sometimes called the fingerprint) is referenced as key ID.
The "key ID" used for RSA key in GPG/PGP is the last 8 hex digits of the modulus of the key.
Having just done this for my own purposes, I'll write this down while it's all fresh in my head...
The "official" key ID (that is, the content of the "X509v3 Subject Key Identifier" extension in an X509 certificate) is the SHA1 hash of the DER-encoded ASN.1 sequence consisting of the modulus and exponent of an RSA public key. It takes piecing together about three different RFCs and a bit of experimentation to come up with that, but that's how it works.
Some Ruby code to do the encoding looks like this -- feed it an RSA public or private key on stdin: