Nacos 2.2.0.1版本 jwtTokenManage问题

错误描述

Error creating bean with name ‘user‘: Unsatisfied dependency expressed through field ‘jwtTokenManagepl. JwtTokenManager]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: the length ofsecret key must great than or equal 32 bytes; And the secret key must be encoded by base64. please see https://nacos.iozh-cn/docs/v2/guide/user/auth.htmlat org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:224)at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)at org.springframework.beans.factory.support.AbstractAutowireCeBeanFactorv.instantiateBean(AbstractAutowireCapableBeanFactory.java:1326)39 common frames omittedCaused by: java.lang.IllegalArgumentException: the length ofgreat than orequal 32 bvtes; And the secreSeCIA1t keymust be encoded by base64. Pleasesee https://nacos.io/zh-cn/docs/v2/quide/user/auth.htmlat com.alibaba.nacos.plugin.auth.impl.JwtTokenManager.processProperties(JwtTokenManager.java:77)at com.alibaba.nacos.plugin.auth,impl.JwtTokenManager,<init>(JwtTokenManager.java:65)at java.base/idk,internal.reflect.NativeConstructorAccessorImpl. newInstance0(Native Method)at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java;490)at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils,java:211)41common framesomittedis 0 bits which is not secure enoughCausedby: io.isonwebtoken.security.WeakKevException: The specified kevbvte arraystates that keys used with HMAC-SHA afor anv JWT HMAC-SHA algorithmTheJWTJWA Specification (RFC 7518Section 3.2)lgorithms MUST have a size256 bits (the kev size must be greaterthan or equal to the hash output size). Consider using the io.jsonwebtoken.security.Keys#secretkeyFor(SignatureAlgorithm) method to create a key quaranteed to be secure enough for your preferred HMAC-SHA algorithmhttps://tools.ietf.org/html/rfc7518#section-3,2 for more informationSeeat io.isonwebtoken.security,Kevs,hmacShaKevFor(Kevs.iava:96)at com.alibaba.nacos.plugin.auth.impl.JwtTokenManager.processProperties(JwtTokenManager.java:75)47 common frames omitted

翻看官方文档说明,需要填充一个默认值


解决方案

在application.properties中配置秘钥

1、自定义密钥

将配置项设置为Base64编码的字符串,且原始密钥长度不得低于32字符

2、使用官方推荐秘钥

SecretKey012345678901234567890123456789012345678901234567890123456789


重新启动nacos即可

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容