secret key byte array cannot be null or empty.
原创
©著作权归作者所有:来自51CTO博客作者wx6316c4e40e2ec的原创作品,请联系作者获取转载授权,否则将追究法律责任
报错信息:java.lang.IllegalArgumentException: secret key byte array cannot be null or empty.
java.lang.IllegalArgumentException: secret key byte array cannot be null or empty.
at io.jsonwebtoken.lang.Assert.notEmpty(Assert.java:199) ~[jjwt-0.6.0.jar:0.6.0]
at io.jsonwebtoken.impl.DefaultJwtBuilder.signWith(DefaultJwtBuilder.java:95) ~[jjwt-0.6.0.jar:0.6.0]
at io.jsonwebtoken.impl.DefaultJwtBuilder.signWith(DefaultJwtBuilder.java:107) ~[jjwt-0.6.0.jar:0.6.0]
at com.fh.jwt.JWTUtil.createToken(JWTUtil.java:37) ~[classes/:na]
at com.fh.user.service.impl.AdminServiceImpl.login(AdminServiceImpl.java:70) ~[classes/:na]
at com.fh.user.service.impl.AdminServiceImpl$$FastClassBySpringCGLIB$$436de677.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:687) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at com.fh.user.service.impl.AdminServiceImpl$$EnhancerBySpringCGLIB$$fcb806d8.login(<generated>) ~[classes/:na]
at com.fh.controller.LoginController.login(LoginController.java:29) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_201]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_201]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_201]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_201]
JWT 生成token时报错:secret key byte array cannot be null or empty.
原因是:生成token的密钥字符串过短引起的异常,
解决方案:密钥字符串加长
效果: