공부 흔적남기기

JWT signature does not match locally computed signature. JWT validity cannot be asserted and should not be trusted. 본문

web study

JWT signature does not match locally computed signature. JWT validity cannot be asserted and should not be trusted.

65살까지 코딩 2025. 1. 22. 22:50
728x90
반응형

분명히 같은 키를 사용하고 똑같은 알고리즘을 통해서 암호화 복호화를 하는데 에러가 나서 삽질을 했다.. 

 JWT signature does not match locally computed signature. JWT validity cannot be asserted and should not be trusted.

 

 

수정전 코드 토큰 발급 

val token = Jwts.builder()
                .subject(user.userId)
                .expiration(Date(System.currentTimeMillis() + jwtProperties.expire))
                .signWith(key, Jwts.SIG.HS256)
                .compact()

 

수정 후 코드 토큰 발급

 

val token = Jwts.builder()
    .subject(user.userId)
    .expiration(Date(System.currentTimeMillis() + jwtProperties.expire))
    .signWith(key)
    .compact()

 

당연히 SignWith를 할떄 Jwts.SIG.HS256 를 명시해주는게 좋을거라고 생각했지만 삽질의 원인이 되었다.

설마하고  Jwts.SIG.HS256를 뺴보았더니 잘 되었다.. 

복호화 코드

Jwts.parser().verifyWith(secretKey).build().parseSignedClaims(jwt).payload.subject

 

 

728x90
반응형