目录
1、报错情况
Caused by: java.lang.IllegalArgumentException: The specified key byte array is 192 bits which is not secure enough for any JWT HMAC-SHA algorithm. The JWT JWA Specification (RFC 7518, Section 3.2) states that keys used with HMAC-SHA algorithms MUST have a size >= 256 bits (the key size must be greater than or equal to the hash output size). See https://tools.ietf.org/html/rfc7518#section-3.2 for more information.
at com.alibaba.nacos.plugin.auth.impl.jwt.NacosJwtParser.<init>(NacosJwtParser.java:56)
at com.alibaba.nacos.plugin.auth.impl.token.impl.JwtTokenManager.processProperties(JwtTokenManager.java:71)
2、报错原因
跟据报错情况分析,是因为指定的密钥字节数组是0位,这对于任何JWT HMAC-SHA算法来说都不够安全。JWT JWA规范(RFC 7518,第3.2节)规定,与HMAC-SHA算法一起使用的密钥必须具有>=256位(也就是32字节)的大小(密钥大小必须大于或等于哈希输出大小)。
3、解决方法
修改配置文件conf/application.propertise的nacos.core.auth.plugin.nacos.token.secret.key选项
添加大于32个字节的任意字符
nacos.core.auth.plugin.nacos.token.secret.key=qwe1rty2ui3opl4kjh5gf6dsazx7cvbnm
配置完后,重启服务就可以正常启动。