io.jsonwebtoken.SignatureException: JWT signature does not match locally computed signature. JWT val

这篇具有很好参考价值的文章主要介绍了io.jsonwebtoken.SignatureException: JWT signature does not match locally computed signature. JWT val。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

jwt signature does not match locally computed signature. jwt validity cannot,java,spring,servlet,spring boot,intellij-idea

io.jsonwebtoken.SignatureException: JWT signature does not match locally computed signature. JWT validity cannot be asserted and should not be trusted.
    at io.jsonwebtoken.impl.DefaultJwtParser.parse(DefaultJwtParser.java:354)
    at io.jsonwebtoken.impl.DefaultJwtParser.parse(DefaultJwtParser.java:481)
    at io.jsonwebtoken.impl.DefaultJwtParser.parseClaimsJws(DefaultJwtParser.java:541)
    at com.example.mz.helpwork.util.JwtUtil.parseJWT(JwtUtil.java:107)
    at com.example.mz.helpwork.config.jwt.JwtAuthenticationTokenFilter.doFilterInternal(JwtAuthenticationTokenFilter.java:39)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:92)
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:77)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1594)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:750)
11:27:19  ERROR  Servlet.service() for servlet [dispatcherServlet] in context with path [/helpwork] threw exception
java.lang.RuntimeException: token非法 

 这个报错翻译成大白话就是io.jsonwebtoken.SignatureException:JWT签名与本地计算的签名不匹配。JWT的有效性无法断言,也不应受到信任。

我是在我的项目中引入springsecurity+jwt时出现的问题

当遇到这个问题的时候,首先是打断点,判断是哪里出现了问题,我的项目在我生成token的时候是没有任何问题的,就是到解析的时候,解析不出来,直接抛出异常。当然针对这个问题,有两种解决方案:更改jwt的工具类;改解析token的代码

当然,我选择的是前者

可以参考我的jwt工具类

    //    这个方法的作用是生成令牌字符串,根据userId生成,生成令牌三个素材:密钥 过期时间 userId
    public String createToken(int userId){
//        对日期做偏移,算一下5天后的日期。new Date()是当前日期 DateField.DAY_OF_YEAR是偏移单位
//        date是偏移之后的日期
        Date date=DateUtil.offset(new Date(), DateField.DAY_OF_YEAR,expire);
//       创建加密算法密钥的对象,调用Algorithm.HMAC256(secret)的静态工厂方法创建对象
        Algorithm algorithm=Algorithm.HMAC256(secret);
//        执行加密
        JWTCreator.Builder builder= JWT.create();
        String token=builder.withClaim("userId",userId).withExpiresAt(date).sign(algorithm);
        return token;
    }

    //    通过令牌解密出userId
    public int getUserId(String token){
//        解码的对象
        DecodedJWT jwt=JWT.decode(token);
//        通过属性名反向得到userid,asInt()是数据类型
        int userId=jwt.getClaim("userId").asInt();
        return userId;
    }

    //    验证令牌,没有返回值,失败抛异常
    public void verifierToken(String token){
//        创建算法对象
        Algorithm algorithm=Algorithm.HMAC256(secret);
//        用算法对象进行解密
        JWTVerifier verifier=JWT.require(algorithm).build();
//        调用验证方法,传入token
        verifier.verify(token);
    }

最终的结果就是解析成功的,如图 

 jwt signature does not match locally computed signature. jwt validity cannot,java,spring,servlet,spring boot,intellij-idea

 文章来源地址https://www.toymoban.com/news/detail-768661.html

到了这里,关于io.jsonwebtoken.SignatureException: JWT signature does not match locally computed signature. JWT val的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • error: src refspec main does not match any解决办法

    用GitHub Actions自动部署Hexo,到了最关键的一步;突然报错:error: src refspec main does not match any 1、错误一:  main 分支应填写为master分支;但是只改这里也会报其他错误 2、错误二: ! [rejected] main - main (non-fast-forward) 这个问题解释起来很简单,还记得我们创建仓库时添加到README和

    2024年02月19日
    浏览(31)
  • git 报错 error: src refspec master does not match any

    这个错误通常表示你的本地仓库中没有与远程仓库对应的分支。可能的原因是你还没有进行过任何提交或者还没有将本地分支推送到远程仓库。 以下是几种可能的解决方法: 1.检查是否存在本地分支 使用git branch命令检查本地是否存在分支。如果没有任何结果,说明你还没有

    2024年02月16日
    浏览(35)
  • dpkg:package architecture (aarch64) does not match system (arm64)

    在nx平台下执行  root@root-desktop:~/test$ sudo dpkg -i MyTest_0.2.1.0_aarch64.deb  dpkg: error processing archive MyTest_0.2.1.0_aarch64.deb (--install):  package architecture (aarch64) does not match system (arm64) Errors were encountered while processing: MyTest_0.2.1.0_aarch64.deb root@root-desktop:~/test$ uname -a Linux rootdesktop 4.9.201-tegra

    2023年04月22日
    浏览(61)
  • 解决./composer.json" does not match the expected JSON schema

    如果执行composer install的时候报错 这是因为name里的格式不符合要求,需要 有/   ,并且不能有大写,仔细检查下正则那句话 无语!

    2024年02月16日
    浏览(48)
  • git push 报错 error: src refspec master does not match any 解决

    真是TN的邪了门了,今天在Gitee上创建了一个新项目,然后要把本地的代码push上去时,报了如下错误: 用了这么多年git也没见过这个啊 咱们哪见过这种场面啊,赶紧百度走起来。 网上啊,真是什么五花八门的说法都有。 但是这时,注意嗷,很快嗷,我发现本地分支名为 ma

    2024年02月11日
    浏览(41)
  • git push时报错error: src refspec dev does not match any

    这种情况可能两种情况导致: 一.分支不存在,使用checkout创建对应分支 切换到新的分支 命令如下: 1 git checkout [branch name] 例如: 1 $ git checkout dev 2 Switched to branch \\\'dev\\\' 4、创建+切换分支 创建分支的同时切换到该分支上,命令如下: git checkout -b [branch name] git checkout -b [branch n

    2024年02月05日
    浏览(32)
  • pandas字段分列遇到ValueError: Length of values does not match length of index

    在使用pandas针对字段进行分列时遇到这个问题,ValueError: Length of values does not match length of index。 问题描述 例如:针对字段进行分列 data[\\\'time\\\'] = data[\\\'time\\\'].astype(str) data[\\\'day\\\'] = data[\\\'time\\\'].str.split(\\\" \\\")[0] data[\\\'hour\\\'] = data[\\\'time\\\'].str.split(\\\" \\\")[1] 原来是语句写错了,这里只需要改成:

    2023年04月12日
    浏览(36)
  • [match_phrase_prefix] query does not support [zero_terms_query] 问题解决

    @[TOC][match_phrase_prefix] query does not support [zero_terms_query] 问题解决 elasticsearch版本 :7.8 客户端elasticsearch : 7.12.1 报错代码 match_phrase_prefix在Elasticsearch 7.10版本后才支持zero_terms_query选项 https://github.com/elastic/elasticsearch/issues/58468

    2024年02月16日
    浏览(35)
  • 完美解决丨ValueError: time data ‘2018/12/24‘ does not match format ‘%Y/%m/%d‘

    这里我选择的是: ```python from datetime import datetime date = datetime.strptime(\\\'2018/12/24\\\', \\\'%Y/%m/%d\\\') ``` 如果你可以执行这段代码,那么你可能会收到这样的报错: ```python Traceback (most recent call last): File \\\"C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesIPythoncoreinteractiveshell.

    2023年04月25日
    浏览(47)
  • The given SOAPAction http__xxxxx_xx does not match an operation

    这是在客户端调用服务端接口时报出的错误,主要是客户端在调用时设置了SOAPAction,参考如下: 解决方案 在注解 @WebMethod() 中加上action注解,设置上一模一样的SOAPAction即可,如下: 添加后,可以重新看下服务端的wsdl文件,确认SOAPAction属性是否成功赋值。

    2024年02月07日
    浏览(27)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包