本文整理了Java中com.auth0.jwt.algorithms.Algorithm.HMAC512()
方法的一些代码示例,展示了Algorithm.HMAC512()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Algorithm.HMAC512()
方法的具体详情如下:
包路径:com.auth0.jwt.algorithms.Algorithm
类名称:Algorithm
方法名:HMAC512
[英]Creates a new Algorithm instance using HmacSHA512. Tokens specify this as "HS512".
[中]使用HmacSHA512创建新的算法实例。令牌将其指定为“HS512”。
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldPassHMAC512Verification() throws Exception {
String jwt = "eyJhbGciOiJIUzUxMiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.VUo2Z9SWDV-XcOc_Hr6Lff3vl7L9e5Vb8ThXpmGDFjHxe3Dr1ZBmUChYF-xVA7cAdX1P_D4ZCUcsv3IefpVaJw";
Algorithm algorithmString = Algorithm.HMAC512("secret");
Algorithm algorithmBytes = Algorithm.HMAC512("secret".getBytes(StandardCharsets.UTF_8));
DecodedJWT decoded = JWT.decode(jwt);
algorithmString.verify(decoded);
algorithmBytes.verify(decoded);
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldCreateHMAC512AlgorithmWithBytes() throws Exception {
Algorithm algorithm = Algorithm.HMAC512("secret".getBytes(StandardCharsets.UTF_8));
assertThat(algorithm, is(notNullValue()));
assertThat(algorithm, is(instanceOf(HMACAlgorithm.class)));
assertThat(algorithm.getDescription(), is("HmacSHA512"));
assertThat(algorithm.getName(), is("HS512"));
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldCreateHMAC512AlgorithmWithString() throws Exception {
Algorithm algorithm = Algorithm.HMAC512("secret");
assertThat(algorithm, is(notNullValue()));
assertThat(algorithm, is(instanceOf(HMACAlgorithm.class)));
assertThat(algorithm.getDescription(), is("HmacSHA512"));
assertThat(algorithm.getName(), is("HS512"));
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldCreateAnEmptyHMAC512SignedToken() throws Exception {
String signed = JWT.create().sign(Algorithm.HMAC512("secret"));
assertThat(signed, is(notNullValue()));
String[] parts = signed.split("\\.");
String headerJson = new String(Base64.decodeBase64(parts[0]), StandardCharsets.UTF_8);
assertThat(headerJson, JsonMatcher.hasEntry("alg", "HS512"));
assertThat(headerJson, JsonMatcher.hasEntry("typ", "JWT"));
assertThat(parts[1], is("e30"));
JWTVerifier verified = JWT.require(Algorithm.HMAC512("secret"))
.build();
assertThat(verified, is(notNullValue()));
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldAcceptHMAC512Algorithm() throws Exception {
String token = "eyJhbGciOiJIUzUxMiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.VUo2Z9SWDV-XcOc_Hr6Lff3vl7L9e5Vb8ThXpmGDFjHxe3Dr1ZBmUChYF-xVA7cAdX1P_D4ZCUcsv3IefpVaJw";
DecodedJWT jwt = JWT.require(Algorithm.HMAC512("secret"))
.build()
.verify(token);
assertThat(jwt, is(notNullValue()));
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldThrowHMAC512InstanceWithNullSecret() throws Exception {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("The Secret cannot be null");
String secret = null;
Algorithm.HMAC512(secret);
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldThrowHMAC512InstanceWithNullSecretBytes() throws Exception {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("The Secret cannot be null");
byte[] secret = null;
Algorithm.HMAC512(secret);
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldFailHMAC512VerificationWithInvalidSecretBytes() throws Exception {
exception.expect(SignatureVerificationException.class);
exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: HmacSHA512");
String jwt = "eyJhbGciOiJIUzUxMiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.VUo2Z9SWDV-XcOc_Hr6Lff3vl7L9e5Vb8ThXpmGDFjHxe3Dr1ZBmUChYF-xVA7cAdX1P_D4ZCUcsv3IefpVaJw";
Algorithm algorithm = Algorithm.HMAC512("not_real_secret".getBytes(StandardCharsets.UTF_8));
algorithm.verify(JWT.decode(jwt));
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldDoHMAC512SigningWithBytes() throws Exception {
Algorithm algorithm = Algorithm.HMAC512("secret".getBytes(StandardCharsets.UTF_8));
String jwt = asJWT(algorithm, HS512Header, auth0IssPayload);
String expectedSignature = "OXWyxmf-VcVo8viOiTFfLaEy6mrQqLEos5R82Xsx8mtFxQadJAQ1aVniIWN8qT2GNE_pMQPcdzk4x7Cqxsp1dw";
assertSignaturePresent(jwt);
assertSignatureValue(jwt, expectedSignature);
algorithm.verify(JWT.decode(jwt));
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldFailHMAC512VerificationWithInvalidSecretString() throws Exception {
exception.expect(SignatureVerificationException.class);
exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: HmacSHA512");
String jwt = "eyJhbGciOiJIUzUxMiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.VUo2Z9SWDV-XcOc_Hr6Lff3vl7L9e5Vb8ThXpmGDFjHxe3Dr1ZBmUChYF-xVA7cAdX1P_D4ZCUcsv3IefpVaJw";
Algorithm algorithm = Algorithm.HMAC512("not_real_secret");
algorithm.verify(JWT.decode(jwt));
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldPassHMAC512Verification() throws Exception {
String token = "eyJhbGciOiJIUzUxMiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.VUo2Z9SWDV-XcOc_Hr6Lff3vl7L9e5Vb8ThXpmGDFjHxe3Dr1ZBmUChYF-xVA7cAdX1P_D4ZCUcsv3IefpVaJw";
Algorithm algorithm = Algorithm.HMAC512("secret");
JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();
concurrentVerify(verifier, token);
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldDoHMAC512SigningWithString() throws Exception {
Algorithm algorithm = Algorithm.HMAC512("secret");
String jwt = asJWT(algorithm ,HS512Header, auth0IssPayload);
String expectedSignature = "OXWyxmf-VcVo8viOiTFfLaEy6mrQqLEos5R82Xsx8mtFxQadJAQ1aVniIWN8qT2GNE_pMQPcdzk4x7Cqxsp1dw";
assertSignaturePresent(jwt);
assertSignatureValue(jwt, expectedSignature);
algorithm.verify(JWT.decode(jwt));
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldThrowWhenAlgorithmDoesntMatchTheTokensAlgorithm() throws Exception {
exception.expect(AlgorithmMismatchException.class);
exception.expectMessage("The provided Algorithm doesn't match the one defined in the JWT's Header.");
JWTVerifier verifier = JWTVerifier.init(Algorithm.HMAC512("secret")).build();
verifier.verify("eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.s69x7Mmu4JqwmdxiK6sesALO7tcedbFsKEEITUxw9ho");
}
代码示例来源:origin: yunTerry/spring-cloud-netflix
public TokenController() {
if (algorithm == null) {
try {
String key = "hd%34#$soe";
algorithm = Algorithm.HMAC512(key);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: SoftInstigate/restheart
private Algorithm getHMAC(String name, byte[] key)
throws IllegalArgumentException {
if ("HMAC256".equals(name) || "HS256".equals(name)) {
return Algorithm.HMAC256(key);
} else if ("HMAC384".equals(name) || "HS384".equals(name)) {
return Algorithm.HMAC384(key);
} else if ("HMAC512".equals(name) || "HS512".equals(name)) {
return Algorithm.HMAC512(key);
} else {
throw new IllegalArgumentException("unknown HMAC algorithm " + name);
}
}
代码示例来源:origin: org.nuxeo.ecm.platform/nuxeo-platform-login-jwt
protected Algorithm getAlgorithm() {
String secret = registry.getContribution().getSecret();
if (isBlank(secret)) {
return null;
}
return Algorithm.HMAC512(secret);
}
代码示例来源:origin: mvetsch/JWT4B
return Algorithm.HMAC512(key);
内容来源于网络,如有侵权,请联系作者删除!