本文整理汇总了Java中com.auth0.jwt.algorithms.Algorithm.HMAC512属性的典型用法代码示例。如果您正苦于以下问题:Java Algorithm.HMAC512属性的具体用法?Java Algorithm.HMAC512怎么用?Java Algorithm.HMAC512使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.auth0.jwt.algorithms.Algorithm
的用法示例。
在下文中一共展示了Algorithm.HMAC512属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJwtToken
private String getJwtToken(String userId) {
try {
Algorithm algorithm = Algorithm.HMAC512(config.server.secret);
return JWT.create()
.withClaim("userId", userId)
.sign(algorithm);
} catch (Exception e) {
return null;
}
}
示例2: getIdFromToken
public static String getIdFromToken(Config config, String token) {
try {
Algorithm algorithm = Algorithm.HMAC512(config.server.secret);
JWTVerifier verifier = JWT.require(algorithm)
.build();
DecodedJWT decodedJWT = verifier.verify(token);
return decodedJWT.getClaim("userId").asString();
} catch (Exception e) {
return null;
}
}
示例3: getAlgorithm
private static Algorithm getAlgorithm(String algo, String key, boolean IsKeyASignerKey)
throws IllegalArgumentException, UnsupportedEncodingException {
if (algo.equals(HS256.getAlgorithm())) {
return Algorithm.HMAC256(key);
}
if (algo.equals(HS384.getAlgorithm())) {
return Algorithm.HMAC384(key);
}
if (algo.equals(HS512.getAlgorithm())) {
return Algorithm.HMAC512(key);
}
if (algo.equals(ES256.getAlgorithm())) {
return Algorithm.ECDSA256((ECKey) getKeyInstance(key, "EC", IsKeyASignerKey));
}
if (algo.equals(ES384.getAlgorithm())) {
return Algorithm.ECDSA384((ECKey) getKeyInstance(key, "EC", IsKeyASignerKey));
}
if (algo.equals(ES512.getAlgorithm())) {
return Algorithm.ECDSA512((ECKey) getKeyInstance(key, "EC",IsKeyASignerKey));
}
if (algo.equals(RS256.getAlgorithm())) {
return Algorithm.RSA256((RSAKey) getKeyInstance(key, "RSA", IsKeyASignerKey));
}
if (algo.equals(RS384.getAlgorithm())) {
return Algorithm.RSA384((RSAKey) getKeyInstance(key, "RSA", IsKeyASignerKey));
}
if (algo.equals(RS512.getAlgorithm())) {
return Algorithm.RSA512((RSAKey) getKeyInstance(key, "RSA", IsKeyASignerKey));
}
return Algorithm.none();
}
示例4: shouldPassHMAC512Verification
@Test
public void shouldPassHMAC512Verification() throws Exception {
String token = "eyJhbGciOiJIUzUxMiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.VUo2Z9SWDV-XcOc_Hr6Lff3vl7L9e5Vb8ThXpmGDFjHxe3Dr1ZBmUChYF-xVA7cAdX1P_D4ZCUcsv3IefpVaJw";
Algorithm algorithm = Algorithm.HMAC512("secret");
JWT jwt = JWT.require(algorithm).withIssuer("auth0").build();
concurrentVerify(jwt, token);
}