本文整理汇总了Java中org.jose4j.jws.JsonWebSignature.setDoKeyValidation方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWebSignature.setDoKeyValidation方法的具体用法?Java JsonWebSignature.setDoKeyValidation怎么用?Java JsonWebSignature.setDoKeyValidation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jose4j.jws.JsonWebSignature
的用法示例。
在下文中一共展示了JsonWebSignature.setDoKeyValidation方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateToken
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
public String generateToken(String subject) {
final JwtClaims claims = new JwtClaims();
claims.setSubject(subject);
claims.setExpirationTimeMinutesInTheFuture(TOKEN_EXPIRATION_IN_MINUTES);
final JsonWebSignature jws = new JsonWebSignature();
jws.setPayload(claims.toJson());
jws.setAlgorithmHeaderValue(HMAC_SHA256);
jws.setKey(new HmacKey(tokenSecret));
jws.setDoKeyValidation(false); //relaxes hmac key length restrictions
try {
return jws.getCompactSerialization();
} catch (JoseException e) {
throw new RuntimeException(e);
}
}
示例2: createToken
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private static String createToken(Key key, JsonObject jsonClaims) {
JwtClaims claims = new JwtClaims();
claims.setSubject(jsonClaims.toString());
claims.setIssuedAtToNow();
claims.setExpirationTime(NumericDate.fromSeconds(NumericDate.now().getValue() + JWT_TOKEN_EXPIRES_TIME));
JsonWebSignature jws = new JsonWebSignature();
jws.setDoKeyValidation(false);
jws.setPayload(claims.toJson());
jws.setKey(key);
jws.setAlgorithmHeaderValue(ALG);
try {
return jws.getCompactSerialization();
} catch (JoseException ex) {
LOGGER.log(Level.SEVERE, null, ex);
}
return null;
}
示例3: createExternalAccountBinding
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
* Creates a JSON structure for external account binding.
*
* @param kid
* Key Identifier provided by the CA
* @param accountKey
* {@link PublicKey} of the account to register
* @param macKey
* {@link SecretKey} to sign the key identifier with
* @param resource
* "newAccount" resource URL
* @return Created JSON structure
*/
private Map<String, Object> createExternalAccountBinding(String kid,
PublicKey accountKey, SecretKey macKey, URL resource)
throws AcmeException {
try {
PublicJsonWebKey keyJwk = PublicJsonWebKey.Factory.newPublicJwk(accountKey);
JsonWebSignature innerJws = new JsonWebSignature();
innerJws.setPayload(keyJwk.toJson());
innerJws.getHeaders().setObjectHeaderValue("url", resource);
innerJws.getHeaders().setObjectHeaderValue("kid", kid);
innerJws.setAlgorithmHeaderValue(macKeyAlgorithm(macKey));
innerJws.setKey(macKey);
innerJws.setDoKeyValidation(false);
innerJws.sign();
JSONBuilder outerClaim = new JSONBuilder();
outerClaim.put("protected", innerJws.getHeaders().getEncodedHeader());
outerClaim.put("signature", innerJws.getEncodedSignature());
outerClaim.put("payload", innerJws.getEncodedPayload());
return outerClaim.toMap();
} catch (JoseException ex) {
throw new AcmeException("Could not create external account binding", ex);
}
}
示例4: generateToken
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
public String generateToken(boolean forcenew) {
JwtClaims claims = new JwtClaims();
claims.setClaim("appID", appId);
claims.setClaim("userID", userId);
if (keyId != null) {
claims.setClaim("keyID", keyId);
}
claims.setExpirationTimeMinutesInTheFuture(10);
claims.setNotBeforeMinutesInThePast(10);
JsonWebSignature jws = new JsonWebSignature();
jws.setPayload(claims.toJson());
jws.setKey(key);
jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256);
// For backwards compatibility with old app secrets
jws.setDoKeyValidation(false);
try {
String jwt = jws.getCompactSerialization();
return jwt;
} catch (JoseException e) {
e.printStackTrace();
}
return null;
}
示例5: toToken
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private static String toToken(byte[] key, JwtClaims claims) {
final JsonWebSignature jws = new JsonWebSignature();
jws.setPayload(claims.toJson());
jws.setAlgorithmHeaderValue(HMAC_SHA256);
jws.setKey(new HmacKey(key));
jws.setDoKeyValidation(false);
try {
return jws.getCompactSerialization();
}
catch (JoseException e) { throw Throwables.propagate(e); }
}
示例6: jwsSign
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private static String jwsSign(Key key, String payload) throws Exception {
JsonWebSignature jws = new JsonWebSignature();
jws.setPayload(payload);
jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA512);
jws.setKey(key);
jws.setDoKeyValidation(false);
return jws.getCompactSerialization();
}
示例7: jwsVerify
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private static String jwsVerify(Key key, String jwt) throws Exception {
JsonWebSignature jws = new JsonWebSignature();
jws.setCompactSerialization(jwt);
jws.setKey(key);
jws.setDoKeyValidation(false);
boolean signatureVerified = jws.verifySignature();
System.out.println("JWS signature verification: " + signatureVerified);
System.out.println("JWT Headers: " + jws.getHeaders().getFullHeaderAsJsonString() );
return jws.getPayload();
}
示例8: verifyJWS
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private void verifyJWS(Key key, String jwt) {
try {
JsonWebSignature jws = new JsonWebSignature();
jws.setKey(key);
jws.setCompactSerialization(jwt);
jws.setDoKeyValidation(false);
assertTrue(jws.verifySignature());
JwtClaims claims = JwtClaims.parse(jws.getPayload());
assertEquals("abc xyz", claims.getSubject());
assertEquals("[email protected]", claims.getClaimValue("email"));
} catch (Exception e) {
fail();
}
}
示例9: createJWT
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
public static String createJWT(final String secret, final String payload) throws JoseException
{
String token;
JsonWebSignature sig = new JsonWebSignature();
//sig.setKey(new HmacKey(DigestUtils.sha256(secret.getBytes(StandardCharsets.UTF_8))));
sig.setKey(new HmacKey(secret.getBytes(StandardCharsets.UTF_8)));
sig.setDoKeyValidation(false);
sig.setPayload(payload);
sig.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256);
sig.setHeader(HeaderParameterNames.TYPE, "JWT");
token = sig.getCompactSerialization();
return token;
}