/** * Generate octet json web key of size string. * * @param size the size * @return the string */ private String generateOctetJsonWebKeyOfSize(final int size) { final OctetSequenceJsonWebKey octetKey = OctJwkGenerator.generateJwk(size); final Map<String, Object> params = octetKey.toParams(JsonWebKey.OutputControlLevel.INCLUDE_SYMMETRIC); return params.get("k").toString(); } }
@Override protected String produceThumbprintHashInput() { String template = "{\"k\":\"%s\",\"kty\":\"oct\"}"; String k = getEncoded(); return String.format(template, k); } }
public OctetSequenceJsonWebKey(Map<String, Object> params) throws JoseException { super(params); Base64Url base64Url = new Base64Url(); String b64KeyBytes = getStringRequired(params, KEY_VALUE_MEMBER_NAME); octetSequence = base64Url.base64UrlDecode(b64KeyBytes); // um... how could I know the alg? I don't see a reliable way to know. // Maybe infer from the alg parameter but it's optional. // Currently it's really either AES or HMAC and only the AES algorithm // implementations seem to actually care. So I'm gonna just go w/ AES for now. String alg = AesKey.ALGORITHM; key = new SecretKeySpec(octetSequence, alg); removeFromOtherParams(KEY_VALUE_MEMBER_NAME); }
public static void generate() throws Exception { byte[] bytes = ByteUtil.randomBytes(ByteUtil.byteLength(512)); OctetSequenceJsonWebKey key = new OctetSequenceJsonWebKey(new HmacKey(bytes)); key.setKeyId("k" + System.currentTimeMillis()); System.out.println(new JsonWebKeySet(key).toJson(JsonWebKey.OutputControlLevel.INCLUDE_SYMMETRIC)); } }
public static JsonWebKey newJwk(Key key) throws JoseException { if (RSAPublicKey.class.isInstance(key)) { return new RsaJsonWebKey((RSAPublicKey)key); } else if (ECPublicKey.class.isInstance(key)) { return new EllipticCurveJsonWebKey((ECPublicKey)key); } else if (PublicKey.class.isInstance(key)) { throw new JoseException("Unsupported or unknown public key " + key); } else { return new OctetSequenceJsonWebKey(key); } }
public static OctetSequenceJsonWebKey generateJwk(int keyLengthInBits, SecureRandom secureRandom) { byte[] bytes = ByteUtil.randomBytes(ByteUtil.byteLength(keyLengthInBits), secureRandom); return new OctetSequenceJsonWebKey(new AesKey(bytes)); } }
/** * Generate octet json web key of given size . * * @param size the size * @return the key */ public static String generateJsonWebKey(final int size) { val octetKey = OctJwkGenerator.generateJwk(size); val params = octetKey.toParams(JsonWebKey.OutputControlLevel.INCLUDE_SYMMETRIC); return params.get(JSON_WEB_KEY).toString(); }
public static JsonWebKey newJwk(Map<String,Object> params) throws JoseException { String kty = getStringRequired(params, KEY_TYPE_PARAMETER); switch (kty) { case RsaJsonWebKey.KEY_TYPE: return new RsaJsonWebKey(params); case EllipticCurveJsonWebKey.KEY_TYPE: return new EllipticCurveJsonWebKey(params); case OctetSequenceJsonWebKey.KEY_TYPE: return new OctetSequenceJsonWebKey(params); default: throw new JoseException("Unknown key type algorithm: '" + kty + "'"); } }
@Override protected void fillTypeSpecificParams(Map<String, Object> params, OutputControlLevel outputLevel) { if (OutputControlLevel.INCLUDE_SYMMETRIC.compareTo(outputLevel) >= 0) { params.put(KEY_VALUE_MEMBER_NAME, getEncoded()); } }
private static String generateOctetJsonWebKeyOfSize(final int size) { val octetKey = OctJwkGenerator.generateJwk(size); val params = octetKey.toParams(JsonWebKey.OutputControlLevel.INCLUDE_SYMMETRIC); return params.get("k").toString(); }
/** * Generate octet json web key of size string. * * @param size the size * @return the string */ private String generateOctetJsonWebKeyOfSize(final int size) { final OctetSequenceJsonWebKey octetKey = OctJwkGenerator.generateJwk(size); final Map<String, Object> params = octetKey.toParams(JsonWebKey.OutputControlLevel.INCLUDE_SYMMETRIC); return params.get("k").toString(); } }