Unable to execute 'doFinal' with cipher instance
今天项目启动后登录项目,突然爆出Unable to execute 'doFinal' with cipher instance错误。清除cookie登录测试,又不报错了,以前也见过类似问题,因为不影响使用,于是就忽略了,今天又遇到了,特研究一下。
原来,项目中使用Shiro作为认证权限控制框架,问题就出在RememberMe功能的配置上。问题产生的原因是rememberMe的cookie在第二次打开页面后shiro无法解密。
项目配置
@Bean
public RememberMeManager rememberMeManager() {
CookieRememberMeManager rememberMeManager = new CookieRememberMeManager();
//注入自定义cookie(主要是设置寿命, 默认的一年太长)
SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
simpleCookie.setHttpOnly(true);
//设置RememberMe的cookie有效期为7天
simpleCookie.setMaxAge(604800);
rememberMeManager.setCookie(simpleCookie); return rememberMeManager;
}
框架源码
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);
}
rememberMeManager继承了AbstractRememberMeManager,然而AbstractRememberMeManager的构造方法中每次都会重新生成对称加密密钥,意味着每次重启程序都会重新生成一对加解密密钥。
这就会导致了,第一次启动程序shiro使用A密钥加密了cookie,第二次启动程序shiro重新生成了密钥B,当用户访问页面时,shiro会用密钥B去解密上一次用密钥A加密的cookie,导致解密失败,导致报错,所以这不影响用户登录操作(rememberMe失效罢了),所以这种异常只会在程序重启(shiro清除session)第一次打开页面的时候出现。
解决办法:手动设置对称加密秘钥。
//手动设置对称加密秘钥,防止重启系统后系统生成新的随机秘钥,防止导致客户端cookie无效
rememberMeManager.setCipherKey(Base64.decode("6ZmI6I2j3Y+R1aSn5BOlAA=="));
Unable to execute 'doFinal' with cipher instance的更多相关文章
- Unable to execute 'doFinal' with cipher instance [javax.crypto.Cipher@4e025e0a]
org.apache.shiro.crypto.CryptoException: Unable to execute 'doFinal' with cipher instance [javax.cry ...
- Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ...
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ... 这个错误是因为有两个相 ...
- 导入项目时,有关[2016-04-03 20:38:02 - Dex Loader] Unable to execute dex: Multiple dex files 问题
最近我在学习androidUI设计,在网上找了一个UI菜单界面开源代码示例,按照步骤导入项目,运行的时候控制台结果报了如下错误: [2016-04-03 20:38:02 - Dex Loader] ...
- Unable to execute dex: GC overhead limit exceeded
Android打包时下面的错误: Unable to execute dex: GC overhead limit exceeded GC overhead limit exceeded 解决的方法: ...
- Eclipse下Android开发错误之Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace
升级了Android版本后,在运行应用时提示: [2013-11-27 10:37:35 - Dex Loader] Unable to execute dex: java.nio.BufferOve ...
- android Eclipse执行项目提示错误: unable to execute dex: GC orerhead limit exceeded
Eclipse执行项目提示错误: unable to execute dex: GC orerhead limit exceeded 解决方法: 找到Eclipse安装目录的文件,\eclipse\e ...
- Unable to execute dex: java.nio.BufferOverflowException.解决办法
异常提示: [2014-01-16 09:27:35 - Dex Loader] Unable to execute dex: java.nio.BufferOverflowException. Ch ...
- 用Eclipse运行Android版APP(PhoneGap)时出现:Unable to execute dex: Multiple dex files define
这两天遇到点小问题,做个记录: 症状:运行,调试时都报:Unable to execute dex: Multiple dex files define错误,发布后的APP安装到手机后一运行,就提示: ...
- Unable to execute dex: Multiple dex files define Lcom/gl
[2015-04-16 17:42:04 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/gl/softphon ...
随机推荐
- 【CF613D】Kingdom and its Cities 虚树+树形DP
[CF613D]Kingdom and its Cities 题意:给你一棵树,每次询问给出k个关键点,问做多干掉多少个非关键点才能使得所有关键点两两不连通. $n,\sum k\le 10^5$ 题 ...
- 从零开始搭建Go语言开发环境
一步一步,从零搭建Go语言开发环境. 安装Go语言及搭建Go语言开发环境 下载 下载地址 Go官网下载地址:https://golang.org/dl/ Go官方镜像站(推荐):https://gol ...
- [LeetCode] Clone Graph 克隆无向图
Given a reference of a node in a connected undirected graph, return a deep copy (clone) of the graph ...
- phpcms 自定义方法
路径:\install_package\phpcms\libs\functions\extention.func.php <?php //输入栏目ID获取父级栏目名称 function catp ...
- input 设置 width:100% 和padding后宽度超出父节点
input 设置 width:100% 和padding后宽度超出父节点 添加如下css即可: box-sizing: border-box; -webkit-box-sizing: border-b ...
- Windows下64位Apache+PHP+MySQL配置
软件下载 目前,Apache和PHP均未出现官方的64位版本. Apache 64位: http://files.cnblogs.com/liangjie/httpd-2.2.19-win64.rar ...
- sql 2005性能调优
转自:http://www.cnblogs.com/MR_ke/archive/2010/08/25/1807856.html SQL Server在运行一段时间,随着数据的积累,SQL运行效率会逐步 ...
- Selenium 3----控制浏览器操作
控制浏览器窗口大小 eg:将浏览器设置成移动端大小(480*800),进行访问 set_window_size()方法: from selenium import webdriver driver=w ...
- linux命令: 两个查找工具 locate,find
linux 中有很多查找工具,今天主要讲解locate,find两个工具. 1.locate (1)查询系统上预建的文件索引数据库 /var/lib/mlocate/mlocate.db 注意:如果这 ...
- PE就是市盈率的缩写 PB是平均市净率的缩写
PE就是市盈率的缩写 PB是平均市净率的缩写 以下为百科知识 PE Price/Earnings 市盈率 也有叫做PER的,Price/Earnings Ratio 本益比,价格收益比,市盈率 市盈率 ...