/** * Prepare json web token key. * * @param secret the secret * @return the key */ @SneakyThrows public static Key generateJsonWebKey(final String secret) { val keys = new HashMap<String, Object>(2); keys.put("kty", "oct"); keys.put(EncodingUtils.JSON_WEB_KEY, secret); val jwk = JsonWebKey.Factory.newJwk(keys); return jwk.getKey(); }
/** * Prepare json web token key. * * @param secret the secret * @return the key */ private Key prepareJsonWebTokenKey(final String secret) { try { final Map<String, Object> keys = new HashMap<>(2); keys.put("kty", "oct"); keys.put("k", secret); final JsonWebKey jwk = JsonWebKey.Factory.newJwk(keys); return jwk.getKey(); } catch (final Exception e) { throw new IllegalArgumentException(e.getMessage(), e); } }
public JsonWebKeySet(String json) throws JoseException { Map<String,Object> parsed = JsonUtil.parseJson(json); List<Map<String,Object>> jwkParamMapList = (List<Map<String,Object>>) parsed.get(JWK_SET_MEMBER_NAME); if (jwkParamMapList == null) { throw new JoseException("The JSON JWKS content does not include the " + JWK_SET_MEMBER_NAME + " member."); } keys = new ArrayList<>(jwkParamMapList.size()); for (Map<String,Object> jwkParamsMap : jwkParamMapList) { try { JsonWebKey jwk = JsonWebKey.Factory.newJwk(jwkParamsMap); keys.add(jwk); } catch (Exception e) { log.debug("Ignoring an individual JWK in a JWKS due to a problem processing it. JWK params: {} and the full JWKS content: {}. {}", jwkParamsMap, json, e); } } }
JsonWebKey jwk = JsonWebKey.Factory.newJwk( "{\"kty\":\"RSA\"," + "\"n\":\"sXchDaQebHnPiGvyDOAT4saGEUetSyo9MKLOoWFsueri23bOdgWp4Dy1Wl" +
public JsonWebKey getJwkHeaderValue(String name) throws JoseException { Object objectHeaderValue = getObjectHeaderValue(name); Map<String, Object> jwkParams = (Map<String, Object>) objectHeaderValue; return JsonWebKey.Factory.newJwk(jwkParams); }
public static JsonWebKey newJwk(String json) throws JoseException { Map<String, Object> parsed = JsonUtil.parseJson(json); return newJwk(parsed); } }
public static PublicJsonWebKey newPublicJwk(Key publicKey) throws JoseException { JsonWebKey jsonWebKey = JsonWebKey.Factory.newJwk(publicKey); return (PublicJsonWebKey) jsonWebKey; }