1 //手动设置对称加密秘钥,防止重启系统后系统生成新的随机秘钥,防止导致客户端cookie无效 2 rememberMeManager.setCipherKey(Base64.decode("6ZmI6I2j3Y+R1aSn5BOlAA=="));
Unable to execute 'doFinal' with cipher instance
to with 39 unable Instance execute Cipher
2023-09-27 14:21:42 时间
今天项目启动后登录项目,突然爆出Unable to execute 'doFinal' with cipher instance错误。清除cookie登录测试,又不报错了,以前也见过类似问题,因为不影响使用,于是就忽略了,今天又遇到了,特研究一下。
原来,项目中使用Shiro作为认证权限控制框架,问题就出在RememberMe功能的配置上。问题产生的原因是rememberMe的cookie在第二次打开页面后shiro无法解密。
项目配置
@Bean 2 public RememberMeManager rememberMeManager() { 3 CookieRememberMeManager rememberMeManager = new CookieRememberMeManager(); 4 //注入自定义cookie(主要是设置寿命, 默认的一年太长) 5 SimpleCookie simpleCookie = new SimpleCookie("rememberMe"); 6 simpleCookie.setHttpOnly(true); 7 //设置RememberMe的cookie有效期为7天 8 simpleCookie.setMaxAge(604800); 9 rememberMeManager.setCookie(simpleCookie);10 return rememberMeManager; 11 }
框架源码
1 public AbstractRememberMeManager() { 2 this.serializer = new DefaultSerializer<PrincipalCollection>(); 3 AesCipherService cipherService = new AesCipherService(); 4 this.cipherService = cipherService; 5 setCipherKey(cipherService.generateNewKey().getEncoded()); 6 } 7 8 public void setCipherKey(byte[] cipherKey) { 9 //Since this method should only be used in symmetric ciphers 10 //(where the enc and dec keys are the same), set it on both: 11 setEncryptionCipherKey(cipherKey); 12 setDecryptionCipherKey(cipherKey); 13 }
rememberMeManager继承了AbstractRememberMeManager,然而AbstractRememberMeManager的构造方法中每次都会重新生成对称加密密钥,意味着每次重启程序都会重新生成一对加解密密钥。
这就会导致了,第一次启动程序shiro使用A密钥加密了cookie,第二次启动程序shiro重新生成了密钥B,当用户访问页面时,shiro会用密钥B去解密上一次用密钥A加密的cookie,导致解密失败,导致报错,所以这不影响用户登录操作(rememberMe失效罢了),所以这种异常只会在程序重启(shiro清除session)第一次打开页面的时候出现。
解决办法:手动设置对称加密秘钥。
转载于:https://www.cnblogs.com/guanghe/p/10689662.html 、https://blog.csdn.net/weixin_30737363/article/details/99022371
相关文章
- WebStorm failing to start with 'idea.system.path' error
- 在 Spring 4.3.9下升级 Velocity 1.7.x to Velocity 2.0.x 出现的问题
- Welcome to IntelliJ IDEA leaning decoument
- echarts 中使用中国地图 前台调试工具持续报错: Uncaught DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0,
- react中报错Failed to set an indexed property on 'CSSStyleDeclaration': Index property setter is not supported
- ERROR 2013 (HY000): Lost connection to MySQL server at 'waiting for initial communication packet', system error: 2
- mysql 数据库to_days,str_to_date函数的使用
- [AWS] How to Use SQS as an Event Source for AWS Lambda
- ERROR 2003 (HY000): Can't connect to MySQL server on '129.28.149.240' (111) mysql 无法远程连接
- SVN Access to '/svn/Test/!svn/me' forbidden,不能更新解决办法
- Android ADB server didn't ACK * failed to start daemon * 简单有效的解决方案
- libaio.so.1: undefined reference to `__stack_chk_fail@GLIBC_2.4'
- Sam Altman 山姆奥特曼:如何成功 ?How To Be Successful
- ubuntu下 GCC编译程序出现 undefined reference to `std::ios_base::Init::Init()'问题
- nohup 命令(设置后台进程): appending output to ‘nohup.out’ 问题
- Task handler raised error: ValueError('not enough values to unpack (expected 3, got 0)')
- warning:deprecated conversion from string constant to 'char *' 解决方案
- TO_CHAR格式化
- springboot启动报错 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
- 【Nov 14th to 20th 】Personal work record
- hdu 6827 Road To The 3rd Building
- [HOW TO]-下载android官方源码
- How to kill server when seeing “EADDRINUSE: address already in use”
- How to make eclipse/pydev happy to see flask extensions on windows?
- Ubuntu 14.04 – How to install xrdp in Ubuntu 14.04
- BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler错误的解决方法
- PDF to DWG Converter 2023 crack
- samtools faidx输出的fai文件格式解析 | fasta转bed | fasta to bed
- invalid conversion from 'void* (*)()' to 'void* (*)(void*)'
- Unable to add window -- token null is not valid; is your activity running?
- npm tip: go to the package's home page
- Unable to use slave's temporary directory /tmp - Can't create/write to file '/tmp/SQL_LOAD-' (Errcode: 17)
- nginx 安装时候报错:make: *** No rule to make target `build', needed by `default'. Stop.
- [Windows Azure] How to Manage Cloud Services?
- ES系列之原来copy_to用好了这么香
- How to parse version range
- [解决] Error Code: 1044. Access denied for user 'root'@'%' to database
- 我的Android进阶之旅------>解决Error:Unable to find method 'org.gradle.api.internal.project.ProjectInternal.g