Replies: 2 comments 12 replies
-
I took the liberty of converting your question to a discussion post, and not an issue. tl;dr: Bare PEM-encoded keys do not contain any extra metadata -- at least yours doesn't. There may exist a convention to encode such data, but I'm not aware of a universally accepted standard to encode key ID / algorithm in this format. If there is one, PRs are welcome. the long answer: There are two parts to my answer. The first part is the reason why your particular case would not have worked even if the library was smarter. Please take look at the command you presented: This is especially true for the algorithm part. The "algorithm" that a JWK contains is not something you can easily and automatically compute. For example, for a given RSA key, you could use any of the RS256, RS384, RS512 algorithms. But there's more to it: the key could be used for encryption as well. In such cases the value could now be RSA-OAEP-SHA1, RSA-PKCS1v1.5, etc. So there is just no way to automatically come up with an algorithm unless the user specifically sets one somewhere. The second part of my answer is about our current implementation of DER format parsing. I'm going to admit that I'm not an expert of formats for ASN.1 DER encoded keys. There may very well be an established standard to encode the above information in a DER format that I'm not aware of. But as far as I could gather at the time of writing the support to parse ASN.1 DER keys, I could not find it, and therefore no metadata is currently extracted out of these keys. If there is an established standard, I would greatly appreciate PRs. Now as far as the key ID goes, it could be argued that You can mimic such behavior though: key, _ := jwk.ParseKey(...)
// note, this is not the same as what openssl rsa ... --fingerprint creates
tb, _ := key.Thumbprint(crypto.SHA256)
key.Set(jwk.KeyIDKey, hex.EncodeToString(tb)) |
Beta Was this translation helpful? Give feedback.
-
Many thanks for you answer!
The same result. |
Beta Was this translation helpful? Give feedback.
-
Hello!
There is no error, but
key
does not have KID, Algorithm and so on. What do I do wrong?Beta Was this translation helpful? Give feedback.
All reactions