How to perform jwt token verification in java

Tarun gupta :

I have jwt token with me and passed in below function. its just i need to verify the jwt token. algorithm='HS256'

void  authenticate_web_socket_connection1(String jwtToken){
    String secret="some random key";
        Claims claims = Jwts.parser()
       .setSigningKey(DatatypeConverter.parseBase64Binary(secret))
       .parseClaimsJws(jwtToken).getBody();

Getting below error: ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Exception in thread "main" io.jsonwebtoken.SignatureException: JWT signature does not match locally computed signature. JWT validity cannot be asserted and should not be trusted.

Sebastián Riquelme :

i use this method to get all Claims from token.

private Claims getAllClaimsFromToken(String token) {

   return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();

}

Let me know if works for you.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=168912&siteId=1