@Override public JsonWebKey deriveKey(KeyParameters params, JsonWebKey jwk) throws CryptoException { if (params == null) { throw new IllegalArgumentException( "The 'params' argument may not be null for PBES2 Key derivation"); } Pbes2KeyParameters pbes2Params = Pbes2KeyParameters.cast(params); Pbes2Key derivedJwk = new Pbes2Key(); if (params.hasKeyId()) { derivedJwk.setKeyId(params.getKeyId()); } derivedJwk.setAlgorithm(String.format("PBES2-%s", pbes2Params.getAlgorithm().getHash())); derivedJwk.setKeyValue( deriveBits(CryptoParameters.cast(pbes2Params), jwk, pbes2Params.getKeyLength())); return derivedJwk; }
@Override public JsonWebKeySet createKeySet(KeyParameters params) throws CryptoException { if (params == null) { throw new IllegalArgumentException( "The 'params' argument may not be null for PBES2 Key generation"); } Pbes2KeyParameters pbes2Params = Pbes2KeyParameters.cast(params); Pbes2Key jwk = new Pbes2Key(); if (params.hasKeyId()) { jwk.setKeyId(params.getKeyId()); } if (params.hasAlgorithm()) { jwk.setAlgorithm(params.getAlgorithmString()); } if (pbes2Params.hasPasswordPolicy()) { jwk.put("pwd#policy", pbes2Params.getPasswordPolicy()); } return new JsonWebKeySet(jwk); }