当前位置: 首页>>代码示例>>Java>>正文


Java Algorithm.HMAC256属性代码示例

本文整理汇总了Java中com.auth0.jwt.algorithms.Algorithm.HMAC256属性的典型用法代码示例。如果您正苦于以下问题:Java Algorithm.HMAC256属性的具体用法?Java Algorithm.HMAC256怎么用?Java Algorithm.HMAC256使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.auth0.jwt.algorithms.Algorithm的用法示例。


在下文中一共展示了Algorithm.HMAC256属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testImplicitJwtCreatorNonStandardClaimLongValue

@Test
public void testImplicitJwtCreatorNonStandardClaimLongValue() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = ImplicitJwtCreator.build()
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withIat(TimeUtil.generateRandomIatDateInPast())
            .withNonStandardClaim("nonStandardClaim", 999L)
            .sign(algorithm);
    Verification verification = ImplicitJWT.require(algorithm);
    JWT verifier = verification.createVerifierForImplicit(asList("issuer"), asList("audience"), 1).build();
    DecodedJWT jwt = verifier.decode(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:16,代码来源:ImplicitJwtCreatorTest.java

示例2: testRiscJwtCreatorNonStandardClaimIntegerValue

@Test
public void testRiscJwtCreatorNonStandardClaimIntegerValue() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = RiscJwtCreator.build()
            .withJWTId(jti)
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withNonStandardClaim("nonStandardClaim", 999)
            .withExp(exp)
            .withIat(iat)
            .sign(algorithm);
    Verification verification = RiscJWT.require(algorithm);
    JWT verifier = verification.createVerifierForRisc(jti, asList("issuer"), asList("audience"), 1, 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims, exp);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:18,代码来源:RiscJwtCreatorTest.java

示例3: testExtendedJwtCreatorBase32Encoding

@Test
public void testExtendedJwtCreatorBase32Encoding() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = ExtendedJwtCreator.build()
            .withNbf(nbf)  //this must be called first since ExtendedJwtCreator.build() returns an instance of ExtendedJwtCreator
            .withPicture(PICTURE)
            .withEmail(EMAIL)
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .withName(NAME)
            .signBase32Encoding(algorithm);
    GoogleVerification verification = ExtendedJWT.require(algorithm);
    JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
            NAME, 1, 1, 1).build();
    DecodedJWT jwt = verifier.decode32Bytes(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims, exp);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:21,代码来源:ExtendedJwtCreatorTest.java

示例4: testRiscJwtCreatorInvalidIssuer

@Test
public void testRiscJwtCreatorInvalidIssuer() throws Exception {
    thrown.expect(InvalidClaimException.class);
    thrown.expectMessage("The Claim 'iss' value doesn't match the required one.");
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = RiscJwtCreator.build()
            .withJWTId(jti)
            .withNbf(nbf)
            .withIssuer("invalid")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .sign(algorithm);
    Verification verification = RiscJWT.require(algorithm);
    JWT verifier = verification.createVerifierForRisc(jti, asList("issuer"), asList("audience"), 1, 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:18,代码来源:RiscJwtCreatorTest.java

示例5: testAccessJwtCreatorNonStandardClaimDateValue

@Test
public void testAccessJwtCreatorNonStandardClaimDateValue() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = AccessJwtCreator.build()
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withNonStandardClaim("nonStandardClaim", new Date())
            .withExp(exp)
            .withIat(iat)
            .sign(algorithm);
    Verification verification = AccessJWT.require(algorithm);
    JWT verifier = verification.createVerifierForAccess(asList("issuer"), asList("audience"), 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims, exp);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:17,代码来源:AccessJwtCreatorTest.java

示例6: testImplicitJwtCreatorNonStandardClaimIntegerValue

@Test
public void testImplicitJwtCreatorNonStandardClaimIntegerValue() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = ImplicitJwtCreator.build()
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withIat(TimeUtil.generateRandomIatDateInPast())
            .withNonStandardClaim("nonStandardClaim", 999)
            .sign(algorithm);
    Verification verification = ImplicitJWT.require(algorithm);
    JWT verifier = verification.createVerifierForImplicit(asList("issuer"), asList("audience"), 1).build();
    DecodedJWT jwt = verifier.decode(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:16,代码来源:ImplicitJwtCreatorTest.java

示例7: testImplicitJwtCreatorNonStandardClaimStringValue

@Test
public void testImplicitJwtCreatorNonStandardClaimStringValue() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = ImplicitJwtCreator.build()
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withIat(TimeUtil.generateRandomIatDateInPast())
            .withNonStandardClaim("nonStandardClaim", "nonStandardClaimValue")
            .sign(algorithm);
    Verification verification = ImplicitJWT.require(algorithm);
    JWT verifier = verification.createVerifierForImplicit(asList("issuer"), asList("audience"), 1).build();
    DecodedJWT jwt = verifier.decode(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:16,代码来源:ImplicitJwtCreatorTest.java

示例8: testAccessJwtCreatorNonStandardClaimDoubleValue

@Test
public void testAccessJwtCreatorNonStandardClaimDoubleValue() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = AccessJwtCreator.build()
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withNonStandardClaim("nonStandardClaim", 9.99)
            .withExp(exp)
            .withIat(iat)
            .sign(algorithm);
    Verification verification = AccessJWT.require(algorithm);
    JWT verifier = verification.createVerifierForAccess(asList("issuer"), asList("audience"), 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims, exp);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:17,代码来源:AccessJwtCreatorTest.java

示例9: signToken

private String signToken(User user) {
    try {
        Algorithm algorithm = Algorithm.HMAC256(Constants.JWT_TOKEN_KEY);
        Date expirationDate = Date.from(ZonedDateTime.now().plusHours(24).toInstant());
        Date issuedAt = Date.from(ZonedDateTime.now().toInstant());
        return JWT.create()
                .withIssuedAt(issuedAt)
                .withExpiresAt(expirationDate)
                .withClaim("userId", user.getId())
                .withIssuer("jwtauth")
                .sign(algorithm);
    } catch (UnsupportedEncodingException | JWTCreationException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
 
开发者ID:Petrakus,项目名称:java-jwt-auth,代码行数:16,代码来源:RESTService.java

示例10: testRiscJwtCreatorNonStandardClaimStringValue

@Test
public void testRiscJwtCreatorNonStandardClaimStringValue() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = RiscJwtCreator.build()
            .withJWTId(jti)
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withNonStandardClaim("nonStandardClaim", "nonStandardClaimValue")
            .withExp(exp)
            .withIat(iat)
            .sign(algorithm);
    Verification verification = RiscJWT.require(algorithm);
    JWT verifier = verification.createVerifierForRisc(jti, asList("issuer"), asList("audience"), 1, 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims, exp);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:18,代码来源:RiscJwtCreatorTest.java

示例11: testScopedJwtCreatorBase32Encoding

@Test
public void testScopedJwtCreatorBase32Encoding() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = ScopedJwtCreator.build()
            .withScope("scope")
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .signBase32Encoding(algorithm);
    Verification verification = ScopedJWT.require(algorithm);
    JWT verifier = verification.createVerifierForScoped("scope", asList("issuer"), asList("audience"), 1, 1).build();
    DecodedJWT jwt = verifier.decode32Bytes(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims, exp);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:17,代码来源:ScopedJwtCreatorTest.java

示例12: testExtendedJwtCreatorBase16Encoding

@Test
public void testExtendedJwtCreatorBase16Encoding() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = ExtendedJwtCreator.build()
            .withNbf(nbf)  //this must be called first since ExtendedJwtCreator.build() returns an instance of ExtendedJwtCreator
            .withPicture(PICTURE)
            .withEmail(EMAIL)
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .withName(NAME)
            .signBase16Encoding(algorithm);
    GoogleVerification verification = ExtendedJWT.require(algorithm);
    JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
            NAME, 1, 1, 1).build();
    DecodedJWT jwt = verifier.decode16Bytes(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims, exp);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:21,代码来源:ExtendedJwtCreatorTest.java

示例13: testAccessJwtCreatorBase32Encoding

@Test
public void testAccessJwtCreatorBase32Encoding() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = AccessJwtCreator.build()
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("audience")
            .withExp(exp)
            .withIat(iat)
            .signBase32Encoding(algorithm);
    Verification verification = AccessJWT.require(algorithm);
    JWT verifier = verification.createVerifierForAccess(asList("issuer"), asList("audience"), 1, 1).build();
    DecodedJWT jwt = verifier.decode32Bytes(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims, exp);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:16,代码来源:AccessJwtCreatorTest.java

示例14: testFbJwtCreatorArrayClaim

@Test
public void testFbJwtCreatorArrayClaim() throws Exception {
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = FbJwtCreator.build()
            .withExp(exp)
            .withIat(iat)
            .withUserId(USER_ID)
            .withAppId(APP_ID)
            .setIsNoneAlgorithmAllowed(true)
            .withArrayClaim("arrayKey", "arrayValue1", "arrayValue2")
            .sign(algorithm);
    Verification verification = FbJWT.require(algorithm);
    JWT verifier = verification.createVerifierForFb(USER_ID, APP_ID).build();
    DecodedJWT jwt = verifier.decode(token);
    Map<String, Claim> claims = jwt.getClaims();
    verifyClaims(claims);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:17,代码来源:FbJwtCreatorTest.java

示例15: testRiscJwtCreatorInvalidAudience

@Test
public void testRiscJwtCreatorInvalidAudience() throws Exception {
    thrown.expect(InvalidClaimException.class);
    thrown.expectMessage("The Claim 'aud' value doesn't contain the required audience.");
    Algorithm algorithm = Algorithm.HMAC256("secret");
    String token = RiscJwtCreator.build()
            .withJWTId(jti)
            .withNbf(nbf)
            .withIssuer("issuer")
            .withSubject("subject")
            .withAudience("invalid")
            .withExp(exp)
            .withIat(iat)
            .sign(algorithm);
    Verification verification = RiscJWT.require(algorithm);
    JWT verifier = verification.createVerifierForRisc(jti, asList("issuer"), asList("audience"), 1, 1, 1).build();
    DecodedJWT jwt = verifier.decode(token);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:18,代码来源:RiscJwtCreatorTest.java


注:本文中的com.auth0.jwt.algorithms.Algorithm.HMAC256属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。