1

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.

Tarun gupta
  • 51
  • 1
  • 8

1 Answers1

1

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.

  • My secret key is called from properties file @Value("${jwt.secret}") private String secret; , so, i dont know if DatatypeConverter is the problem. I think the problem its other. (https://stackoverflow.com/questions/56639392/jwt-signature-does-not-match-locally-computed-signature-jwt-validity-cannot-be) – Sebastián Riquelme Mar 10 '20 at 15:20
  • verification logic was correct but its just i was incorrectly signing the token. so my problem is solved now – Tarun gupta Mar 10 '20 at 16:31