我尝试创建 JWT 令牌
final String jws = Jwts.builder()
.claim("rainId", rainId.toString())
.signWith(SignatureAlgorithm.HS256, TextCodec.BASE64.decode("jwtSecretKey"))
.compact();
然后我尝试解析它
Jws<Claims> jwsClaims = Jwts.parser()
.require("rainId", rainId.toString())
.setSigningKey(TextCodec.BASE64.decode("jwtSecretKey1"))
.parseClaimsJws(jws);
正如您所看到SigningKey的略有不同,所以我预计解析器会失败,但它不会发生。只有SigningKey在解析器中有很大差异时才会发生这种情况。例如“jwtSecretKey111111111111111111111111111111”或“dsfdsfdsfdsfds”。SigningKey如果解析器略有不同,有人可以解释为什么解析器不会失败吗?
我用
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>