JWK JSON public key gerneration.
Issue #79
invalid
Hi Brian, Could you please clarify my doubt regarding JWK JSON public key gerneration. Client provided JSON like { "jwk": [ { "alg": "RSA", "mod": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "exp": "AQAB" } ] } How i can create public key from above JOSN. Could you please help me to slove this. Thanks, Unnikrishnan
Comments (3)
-
repo owner -
repo owner Actually, that's not right. Per https://tools.ietf.org/html/rfc7518#section-6.3 there should be a "kty":"RSA" rather than "alg":"RSA" and an "n" rather than "mod" and "e" rather than "exp"). So more like this:
json = json.replaceFirst("jwk", JsonWebKeySet.JWK_SET_MEMBER_NAME); json = json.replaceFirst(JsonWebKey.ALGORITHM_PARAMETER, JsonWebKey.KEY_TYPE_PARAMETER); json = json.replaceFirst("\"mod\"", "\"" + RsaJsonWebKey.MODULUS_MEMBER_NAME + "\""); json = json.replaceFirst("\"exp\"", "\"" + RsaJsonWebKey.EXPONENT_MEMBER_NAME + "\""); JsonWebKeySet jwks = new JsonWebKeySet(json); JsonWebKey next = jwks.getJsonWebKeys().iterator().next(); Key key = next.getKey(); PublicKey publicKey = (PublicKey) key;
-
repo owner - changed status to invalid
- Log in to comment
Something like this with the just the JSON object from the array:
Or if you can parse that object into a map, there's a PublicJsonWebKey.Factory.newPublicJwk method that takes a map too.
Or something like this to make that JSON into a proper JWKS first and give that to a new JsonWebKeySet object: