sign-key一定要配置256位吗?

Blade 已结 1 174
xMan
xMan 剑者 2024-01-08 17:52

一、该问题的重现步骤是什么?

1. 按照文档配置成了32位的,解析的时候报错。

2. 

Claims aa=Jwts.()
   .setSigningKey().build()
   .parseClaimsJws(jsonWebToken).getBody();

3.


二、你期待的结果是什么?实际看到的又是什么?

32位可以正常解析


三、你正在使用的是什么产品,什么版本?在什么操作系统上?

bladeboot 版2.9.1 windows


四、请提供详细的错误堆栈信息,这很重要。

io.jsonwebtoken.security.WeakKeyException: The verification key's size is 192 bits which is not secure enough for the HS256 algorithm.  The JWT JWA Specification (RFC 7518, Section 3.2) states that keys used with HS256 MUST have a size >= 256 bits (the key size must be greater than or equal to the hash output size).  Consider using the io.jsonwebtoken.security.Keys class's 'secretKeyFor(SignatureAlgorithm.HS256)' method to create a key guaranteed to be secure enough for HS256.  See https://tools.ietf.org/html/rfc7518#section-3.2 for more information.

at io.jsonwebtoken.SignatureAlgorithm.assertValid(SignatureAlgorithm.java:387)

at io.jsonwebtoken.SignatureAlgorithm.assertValidVerificationKey(SignatureAlgorithm.java:328)

at io.jsonwebtoken.impl.DefaultJwtParser.parse(DefaultJwtParser.java:401)

at io.jsonwebtoken.impl.DefaultJwtParser.parse(DefaultJwtParser.java:550)

at io.jsonwebtoken.impl.DefaultJwtParser.parseClaimsJws(DefaultJwtParser.java:610)

at io.jsonwebtoken.impl.ImmutableJwtParser.parseClaimsJws(ImmutableJwtParser.java:173)

at org.springblade.core.jwt.JwtUtil.main(JwtUtil.java:129)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

五、若有更多详细信息,请在下面提供。

1条回答
  •  zhx1994
    zhx1994 (最佳回答者)
    2024-01-09 08:51

    key用这个类生成,org.springblade.test.SignKeyGenerator#main

    NF%BPA`HJ`0TI)FG7FWEM)5.png

    0 讨论(1)
提交回复