Nacos 2.2.0.1版本 jwtTokenManage問(wèn)題

錯(cuò)誤描述

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

翻看官方文檔說(shuō)明,需要填充一個(gè)默認(rèn)值


解決方案

在application.properties中配置秘鑰

1、自定義密鑰

將配置項(xiàng)設(shè)置為Base64編碼的字符串,且原始密鑰長(zhǎng)度不得低于32字符

2、使用官方推薦秘鑰

SecretKey012345678901234567890123456789012345678901234567890123456789


重新啟動(dòng)nacos即可

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容