Unable to execute 'doFinal' with cipher instance [[email protected]]

org.apache.shiro.crypto.CryptoException: Unable to execute ‘doFinal‘ with cipher instance [[email protected]].
    at org.apache.shiro.crypto.JcaCipherService.crypt(JcaCipherService.java:462)
    at org.apache.shiro.crypto.JcaCipherService.crypt(JcaCipherService.java:445)
    at org.apache.shiro.crypto.JcaCipherService.decrypt(JcaCipherService.java:390)
    at org.apache.shiro.crypto.JcaCipherService.decrypt(JcaCipherService.java:382)
    at org.apache.shiro.mgt.AbstractRememberMeManager.decrypt(AbstractRememberMeManager.java:482)
    at org.apache.shiro.mgt.AbstractRememberMeManager.convertBytesToPrincipals(AbstractRememberMeManager.java:419)
    at org.apache.shiro.mgt.AbstractRememberMeManager.getRememberedPrincipals(AbstractRememberMeManager.java:386)
    at org.apache.shiro.mgt.DefaultSecurityManager.getRememberedIdentity(DefaultSecurityManager.java:604)
    at org.apache.shiro.mgt.DefaultSecurityManager.resolvePrincipals(DefaultSecurityManager.java:492)
    at org.apache.shiro.mgt.DefaultSecurityManager.createSubject(DefaultSecurityManager.java:342)
    at org.apache.shiro.subject.Subject$Builder.buildSubject(Subject.java:846)
    at org.apache.shiro.web.subject.WebSubject$Builder.buildWebSubject(WebSubject.java:148)
    at org.apache.shiro.web.servlet.AbstractShiroFilter.createSubject(AbstractShiroFilter.java:292)
    at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:359)
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
    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:200)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
    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:408)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:836)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1747)
    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:748)
Caused by: javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryption.
    at com.sun.crypto.provider.CipherCore.unpad(CipherCore.java:975)
    at com.sun.crypto.provider.CipherCore.fillOutputBuffer(CipherCore.java:1056)
    at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:853)
    at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446)
    at javax.crypto.Cipher.doFinal(Cipher.java:2164)
    at org.apache.shiro.crypto.JcaCipherService.crypt(JcaCipherService.java:459)
    ... 35 more

每次登陆都会报这个错误,尝试了很多次都没解决,代码重编译后清除浏览器cookie登陆就会出现这个报错,虽然不影响登陆但是看着很不爽!!!!

问题产生的原因是rememberMe的cookie在第二次打开页面后shiro无法解密,经过查询资料以及代码跟踪发现了原因所在

先附上rememberMe管理器配置

    @Bean
    public CookieRememberMeManager cookieRememberMeManager() {
        CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
        SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
        simpleCookie.setMaxAge(259200000);
        cookieRememberMeManager.setCookie(simpleCookie);
        return cookieRememberMeManager;
    }

然后跟踪管理器源码发现,rememberMeManager继承了AbstractRememberMeManager,然而AbstractRememberMeManager的构造方法中每次都会重新生成对称加密密钥!!!!意味着每次重启程序都会重新生成一对加解密密钥!!!

    public AbstractRememberMeManager() {
        this.serializer = new DefaultSerializer<PrincipalCollection>();
        AesCipherService cipherService = new AesCipherService();
        this.cipherService = cipherService;
        setCipherKey(cipherService.generateNewKey().getEncoded());
    }

    public void setCipherKey(byte[] cipherKey) {
        //Since this method should only be used in symmetric ciphers
        //(where the enc and dec keys are the same), set it on both:
        setEncryptionCipherKey(cipherKey);
        setDecryptionCipherKey(cipherKey);
    }

这就会导致了,第一次启动程序shiro使用A密钥加密了cookie,第二次启动程序shiro重新生成了密钥B,当用户访问页面时,shiro会用密钥B去解密上一次用密钥A加密的cookie,导致解密失败,导致报错,所以这不影响用户登录操作(rememberMe失效罢了),所以这种异常只会在程序重启(shiro清除session)第一次打开页面的时候出现

解决办法:

既然每次重启都会重新生成一对密钥,那我们就手动设置一个加解密密钥,主动设置cipherkey!!xml配置方式

    <bean id="rememberMeManager" class="org.apache.shiro.web.mgt.CookieRememberMeManager">
        <property name="cipherKey" value="#{T(org.apache.shiro.codec.Base64).decode(‘6ZmI6I2j5Y+R5aSn5ZOlAA==‘)}"/>
        <property name="cookie" ref="rememberCookie"/>     
    </bean>

 

Unable to execute 'doFinal' with cipher instance [[email protected]]

原文地址:https://www.cnblogs.com/deityjian/p/10775656.html

时间: 2024-11-14 14:46:04

Unable to execute 'doFinal' with cipher instance [[email protected]]的相关文章

rabbimq集群搭建报错:Error: unable TO perform an operation ON node &#39;[email&#160;protected]&#39;. Please see diagnostics information AND suggestions below.

在搭建rabbitmq集群的时候,添加内存节点时,抛出异常:Error: unable TO perform an operation ON node '[email protected]'. Please see diagnostics information AND suggestions below. 首先,假设当前服务器为A,我们在A服务器执行rabbitmqctl join_cluster [email protected] --ram,就是说我们要将A服务器作为内存节点加入到B中,然

CentOS中输入yum报错:sudo: unable to execute /bin/yum: No such file or directory

今天尝试更新了下虚拟机CentOS中的python版本后. 运行“yum”命令,就报错:“sudo: unable to execute /bin/yum: No such file or directory” 查询了下网上的资料发现,原来yum调用是用python写的.遂想起刚刚更新python版本,忘了修改yum配置文件了. 解决办法:修改yum配置文件  [[email protected] ~]#vim /usr/bin/yum 把文件头部的#!/usr/bin/python改成#!/u

unable to execute ./start.sh: No such file or directory

刚编写的一个shell文件执行时突然遇到shell文件不能运行,一下子觉得奇了怪了,明明写的shell文件,而且添加了可执行权限,竟然提示这个结果:如下 [[email protected]-2812 opt]$ sudo ./my.sh sudo: unable to execute ./my.sh: No such file or directory 尝试对文件的用vim打开该sh文件,输入:set ff ,显示fileformat=unix,说明没有问题(如果显示fileformat=do

【Android-tips】 Unable to execute dex: Multiple dex files define 解决方法

唔,之前已经想过今后不动android,没想到还是因为比赛的原因重操旧业.android有很多问题是由于eclipse的不完善造成的,比如今天遇到的这个问题 Unable to execute dex: Multiple dex files define [2011-10-23 16:23:29 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/myapp/R$array; [2011-10-23 16:23:

[Android学习笔记]Unable to execute dex Multiple dex files define:xxxx 问题

不同情况可能会出现这个问题,我遇到的问题是: 引入的多个jar包中,其中可能是第三方的SDK,但是其中可能使用了比较流行的开源框架,此时你项目中就有两套包名一样的代码,编译没问题,部署到手机之后就报如上错误 解决办法是: 把第三方jar包包含的开源代码删掉即可 比如: 项目中使用了android-async-http.jar , 同时引入 xxxxx.sdk.jar , 而由于xxxxx.sdk.jar中也引入了android-async-http.jar所以出现以上错误 解决步骤: 1.修改x

app打包时报错unable to execute command: Segmentation fault: 11

问题:打包时报错   clang: error:unable to execute command: Segmentation fault: 11 clang: error:linker command failed due to signal (use -v to see invocation) app在上架的时候遇到这个报错问题,一开始以为是证书或者是配置描述文件哪里出错了.作为新手,在试了好多方法依然无法解决之后,只能无奈按照app上架流程又完完全全的重新过了一遍,在点击Archive后的

Unable to execute dex: method ID not in [0, 0xffff]: 65536 问题解决方法

开始一个新项目的时候,Build工程的时候一直报这个错误: 控制台报错误:Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536 看别人有说在project.properties里面加上dex.force.jumbo=true,尝试了一下,不成功, 后来遍访名山高人,查各种资料,各种尝试,终于成功解决了 原因可能是因为adt升级等原因,在Java_Buildpat

Unable to add window -- token [email&#160;protected] is not valid错误分析记录

打开APP时,出现闪退的情况,查看android studio报错信息,主要为: Unable to add window -- token [email protected] is not valid 原因分析:由于进入APP时会显示一个进度对话框,对话框的初始化必须依赖Activity,但如果对话框的初始化放在Activity的onCreate方法中,那么就会报错. 因为根据Activity的生命周期,onCreate方法执行时,Activity并未创建完毕,对话框所依赖的Activity还

Unable to execute dex: Multiple dex files define Lorg/ap (

解决这个问题的方法,直接把commons-collections.jar这个jar包删除,一定要删干净啊,各个地方看一下,再clean下,应该没问题了!根据这个英文的目录指示就是Unable to execute dex: Multiple dex files define Lorg/apache/commons/collections下的一个类文件和自己定义的冲突了,删掉!