Java Code Examples for com.auth0.jwt.algorithms.Algorithm#HMAC512
The following examples show how to use
com.auth0.jwt.algorithms.Algorithm#HMAC512 .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TokenResponse.java From clouditor with Apache License 2.0 | 6 votes |
User decode(String secret, String issuer) { var algorithm = Algorithm.HMAC512(secret); var verifier = JWT.require(algorithm).withIssuer(issuer).build(); var jwt = verifier.verify(this.idToken); var user = new User(); user.setShadow(true); user.setUsername(jwt.getSubject()); var claim = jwt.getClaim("full_name"); if (!claim.isNull()) { user.setFullName(claim.asString()); } else { user.setFullName(user.getUsername()); } claim = jwt.getClaim("email"); if (!claim.isNull()) { user.setEmail(claim.asString()); } return user; }
Example 2
Source File: Sign.java From staffjoy with MIT License | 6 votes |
static DecodedJWT verifyToken(String tokenString, String signingToken) { JWTVerifier verifier = verifierMap.get(signingToken); if (verifier == null) { synchronized (verifierMap) { verifier = verifierMap.get(signingToken); if (verifier == null) { Algorithm algorithm = Algorithm.HMAC512(signingToken); verifier = JWT.require(algorithm).build(); verifierMap.put(signingToken, verifier); } } } DecodedJWT jwt = verifier.verify(tokenString); return jwt; }
Example 3
Source File: JwtTokenProvider.java From realworld-api-quarkus with MIT License | 5 votes |
public JwtTokenProvider( @ConfigProperty(name = "jwt.issuer") String issuer, @ConfigProperty(name = "jwt.secret") String secret, @ConfigProperty(name = "jwt.expiration.time.minutes") Integer expirationTimeInMinutes) { this.issuer = issuer; this.algorithm = Algorithm.HMAC512(secret); this.jwtVerifier = JWT.require(algorithm).withIssuer(issuer).build(); this.expirationTimeInMinutes = expirationTimeInMinutes; }
Example 4
Source File: Sign.java From staffjoy with MIT License | 5 votes |
private static Algorithm getAlgorithm(String signingToken) { Algorithm algorithm = algorithmMap.get(signingToken); if (algorithm == null) { synchronized (algorithmMap) { algorithm = algorithmMap.get(signingToken); if (algorithm == null) { algorithm = Algorithm.HMAC512(signingToken); algorithmMap.put(signingToken, algorithm); } } } return algorithm; }
Example 5
Source File: AlgorithmLinker.java From JWT4B with GNU General Public License v3.0 | 5 votes |
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(); }
Example 6
Source File: JWTAuthenticationFilter.java From waltz with Apache License 2.0 | 5 votes |
public JWTAuthenticationFilter(SettingsService settingsService) { super(settingsService); try { Algorithm algorithm256 = Algorithm.HMAC256(JWTUtilities.SECRET); Algorithm algorithm512 = Algorithm.HMAC512(JWTUtilities.SECRET); verifier256 = mkVerifier(algorithm256); verifier512 = mkVerifier(algorithm512); } catch (Exception e) { LOG.error("Cannot create JWT Verifier, this is bad", e); throw new UnsupportedOperationException(e); } }
Example 7
Source File: ConcurrentVerifyTest.java From java-jwt with MIT License | 5 votes |
@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); }
Example 8
Source File: JwtCreate.java From openbd-core with GNU General Public License v3.0 | 4 votes |
@Override public cfData execute(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException { // Prep variables Builder tokenBuilder = JWT.create(); String token = ""; Algorithm algo; // Grab the parameters String secret = getNamedStringParam(argStruct, "secret", "" ); String issuer = getNamedStringParam(argStruct, "issuer", "" ); String subject = getNamedStringParam(argStruct, "subject", "" ); String audience = getNamedStringParam(argStruct, "audience", "" ); Integer expiration = getNamedIntParam(argStruct, "expiration", -1 ); String algorithm = getNamedStringParam(argStruct, "algorithm", "HMAC256" ); cfData privateClaims = getNamedParam(argStruct, "private"); if (!privateClaims.isStruct()) throwException(_session, "Parameter isn't of type STRUCTURE"); try { // Set the algorithm, default to HMAC256 if no match switch(algorithm) { case "HMAC384": algo = Algorithm.HMAC384(secret); break; case "HMAC512": algo = Algorithm.HMAC512(secret); break; default: algo = Algorithm.HMAC256(secret); break; } // Set the public claims tokenBuilder.withIssuer(issuer); if (subject.length() > 0) { tokenBuilder.withSubject(subject); } if (audience.length() > 0) { tokenBuilder.withAudience(audience); } if (expiration > -1) { tokenBuilder.withExpiresAt(new Date(expiration)); } // Set the private claims cfStructData struct = (cfStructData) privateClaims; Object[] thekeys = struct.keys(); for ( int i = 0; i < thekeys.length; i++ ) { String key2 = (String)thekeys[ i ]; cfData val = struct.getData( key2 ); if( val.getDataTypeName() == "boolean" ) { tokenBuilder.withClaim(key2, val.getBoolean()); } else { if( cfData.isSimpleValue(val) ){ tokenBuilder.withClaim(key2, val.getString()); } else { // Let's turn our complex data into json StringBuilder buffer = new StringBuilder(5000); // Use the existing openbd json serializer serializejson jsonserializer = new serializejson(); DateType datetype = DateType.LONG; CaseType caseConversion = CaseType.MAINTAIN; jsonserializer.encodeJSON(buffer, val, false, caseConversion, datetype); tokenBuilder.withClaim(key2, buffer.toString()); } } } // Sign and stringify final token token = tokenBuilder.sign(algo); } catch (Exception e) { throwException(_session, e.getMessage()); } return new cfStringData(token); }
Example 9
Source File: JwtVerify.java From openbd-core with GNU General Public License v3.0 | 4 votes |
@Override public cfData execute(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException { String token = getNamedStringParam(argStruct, "token", "" ); String secret = getNamedStringParam(argStruct, "secret", "" ); String issuer = getNamedStringParam(argStruct, "issuer", "" ); String algorithm = getNamedStringParam(argStruct, "algorithm", "HMAC256" ); Algorithm algo; Boolean verified = false; try { // Set the algorithm, default to HMAC256 if no match switch(algorithm) { case "HMAC384": algo = Algorithm.HMAC384(secret); break; case "HMAC512": algo = Algorithm.HMAC512(secret); break; default: algo = Algorithm.HMAC256(secret); break; } try { // If this doesn't throw an error, it's verified Verification verifier = JWT.require(algo); verifier.withIssuer(issuer); @SuppressWarnings("unused") DecodedJWT jwt = verifier.build().verify(token); verified = true; } catch (JWTVerificationException exception){ verified = false; } } catch (Exception e) { throwException(_session, e.getMessage()); } return (verified == true) ? cfBooleanData.TRUE : cfBooleanData.FALSE; }