前几天分享了一篇《Spring Boot 2.x基础教程:加密配置中的敏感信息》 ,然后看到群里有小伙伴反应跟着这篇文章出现了这个异常com.ulisesbocchio.jasyptspringboot.exception.DecryptionException: Unable to decrypt

具体完整的错误信息如下:

Caused by: com.ulisesbocchio.jasyptspringboot.exception.DecryptionException: Unable to decrypt: ENC(/AL9nJENCYCh9Pfzdf2xLPsqOZ6HwNgQ3AnMybFAMeOM5GphZlOK6PxzozwtCm+Q). Decryption of Properties failed,  make sure encryption/decryption passwords match
at com.ulisesbocchio.jasyptspringboot.resolver.DefaultPropertyResolver.lambda$resolvePropertyValue$0(DefaultPropertyResolver.java:46) ~[jasypt-spring-boot-3.0.3.jar:na]
at java.util.Optional.map(Optional.java:215) ~[na:1.8.0_151]
at com.ulisesbocchio.jasyptspringboot.resolver.DefaultPropertyResolver.resolvePropertyValue(DefaultPropertyResolver.java:40) ~[jasypt-spring-boot-3.0.3.jar:na]
at com.ulisesbocchio.jasyptspringboot.resolver.DefaultLazyPropertyResolver.resolvePropertyValue(DefaultLazyPropertyResolver.java:50) ~[jasypt-spring-boot-3.0.3.jar:na]
at com.ulisesbocchio.jasyptspringboot.EncryptablePropertySource.getProperty(EncryptablePropertySource.java:20) ~[jasypt-spring-boot-3.0.3.jar:na]
at com.ulisesbocchio.jasyptspringboot.caching.CachingDelegateEncryptablePropertySource.getProperty(CachingDelegateEncryptablePropertySource.java:41) ~[jasypt-spring-boot-3.0.3.jar:na]
at com.ulisesbocchio.jasyptspringboot.wrapper.EncryptableMapPropertySourceWrapper.getProperty(EncryptableMapPropertySourceWrapper.java:31) ~[jasypt-spring-boot-3.0.3.jar:na]
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:85) ~[spring-core-5.3.8.jar:5.3.8]
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:62) ~[spring-core-5.3.8.jar:5.3.8]
at org.springframework.core.env.AbstractEnvironment.getProperty(AbstractEnvironment.java:588) ~[spring-core-5.3.8.jar:5.3.8]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$1.getProperty(PropertySourcesPlaceholderConfigurer.java:137) ~[spring-context-5.3.8.jar:5.3.8]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$1.getProperty(PropertySourcesPlaceholderConfigurer.java:133) ~[spring-context-5.3.8.jar:5.3.8]
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:85) ~[spring-core-5.3.8.jar:5.3.8]
at org.springframework.core.env.PropertySourcesPropertyResolver.getPropertyAsRawString(PropertySourcesPropertyResolver.java:74) ~[spring-core-5.3.8.jar:5.3.8]
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:159) ~[spring-core-5.3.8.jar:5.3.8]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-5.3.8.jar:5.3.8]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:239) ~[spring-core-5.3.8.jar:5.3.8]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-5.3.8.jar:5.3.8]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175) ~[spring-context-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:936) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1321) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:657) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.8.jar:5.3.8]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.8.jar:5.3.8]
... 69 common frames omitted
Caused by: org.jasypt.exceptions.EncryptionOperationNotPossibleException: null
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:1165) ~[jasypt-1.9.3.jar:na]
at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:738) ~[jasypt-1.9.3.jar:na]
at org.jasypt.encryption.pbe.PooledPBEStringEncryptor.decrypt(PooledPBEStringEncryptor.java:511) ~[jasypt-1.9.3.jar:na]
at com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor.decrypt(DefaultLazyEncryptor.java:57) ~[jasypt-spring-boot-3.0.3.jar:na]
at com.ulisesbocchio.jasyptspringboot.resolver.DefaultPropertyResolver.lambda$resolvePropertyValue$0(DefaultPropertyResolver.java:44) ~[jasypt-spring-boot-3.0.3.jar:na]
... 94 common frames omitted

直接根据错误信息的描述来判断,就是解密失败了。

下面整理一下可能产生解密失败的几种可能:

第一种:推测解密失败的原因是加密和解密使用的密钥不一致,也就是jasypt.encryptor.password的配置和使用插件时候的参数传的不同。

第二种:没有安装不限长度的JCE版本(Unlimited Strength Java Cryptography Extension)。因为DD以前在用Spring Cloud Config的时候已经装过了,所以在写之前这个案例的时候没有提到这点,应该一些还没有接触Spring Cloud的读者通常都是这个原因导致。其实这个在之前的《分布式配置中心(加密解密)》 一文中提过,但因为不属于一个系列内容,这里所以再提一下。

我们可以从Oracle的官方网站中下载你所用Java版本对应的JCE安装包,比如:JCE8下载地址。它是一个压缩包,解压后可以看到下面三个文件:

README.txt
local_policy.jar
US_export_policy.jar

我们需要将local_policy.jarUS_export_policy.jar两个文件复制到$JAVA_HOME/jre/lib/security目录下,覆盖原来的默认内容,这样加密解密的准备工作就完成了。 最后如果你在学习Spring Boot,再推荐一下这个从2016年连载至今的系列教程点击直达,欢迎收藏与转发!如果学习过程中如遇困难?可以加入我们 Spring技术交流群 ,参与交流与讨论,更好的学习与进步!

欢迎关注我的公众号:程序猿DD,分享外面看不到的干货与思考!

使用jasypt加密配置的时候,报错:DecryptionException: Unable to decrypt的更多相关文章

  1. 配置MySQL主从复制报错Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work

    配置MySQL主从复制报错 ``` Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave ha ...

  2. 解决jira配置gmail邮箱报错

    具体报错: AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at 535 ...

  3. Vue项目 invalid host header 问题 配置 disableHostCheck:true报错

    项目场景: 解决 Vue 项目 invalid host header 问题disableHostCheck:true报错 问题描述 使用内网穿透时出现 invalid host header 找了好 ...

  4. 修改ubuntu DNS的步骤/wget url报错: unable to resolve host address的解决方法

    wget url 报错:unable to resolve host address ‘url’,显然是无法解析主机地址,这就能看出是DNS解析的问题.解决办法就是配置可用的dns 一般是修改成为谷歌 ...

  5. java程序报错:Unable to open debugger port (127.0.0.1:63959): java.net.SocketException "socket closed",编译过来就是无法打开调试器端口,套接字已关闭

    报错:Unable to open debugger port (127.0.0.1:63959): java.net.SocketException "socket closed" ...

  6. 解决报错:Unable to process Jar entry [org/springframework/jmx/export/annotation/*****]

    情况说明:从gitub上clone的maven项目,pox.xml配置中的依赖,自己的repository都有,所以正常update project ,正常clean,install,整个过程无报错 ...

  7. npm总是报错:unable to verify the first certificate

    今天npm install总是报错:unable to verify the first certificate(无法验证第一证书),查了一下发现 As of February 27, 2014, n ...

  8. 【Devops】【docker】【CI/CD】Jenkins自动安装JDK需要提供Oracle的账号密码,否则报错:Unable ro auto-install JDK until the license is accepted

    Jenkins自动安装JDK需要提供Oracle的账号密码,否则报错:Unable ro auto-install JDK  until the  license is accepted 解决方法: ...

  9. git同步遇到报错“fatal: unable to access 'https://github.com/lizhong24/mysite2.git/': Peer reports incompatible or unsupported protocol version.”

    git同步遇到报错“fatal: unable to access 'https://github.com/lizhong24/mysite2.git/': Peer reports incompat ...

  10. k8s集群node节点一直NotReady, 且node节点(并非master)的kubelet报错:Unable to update cni config: No networks found in /etc/cni/net.d

    若要转载本文,请务必声明出处:https://www.cnblogs.com/zhongyuanzhao000/p/11401031.html 问题: 集群搭建的过程中,master节点初始化成功,但 ...

随机推荐

  1. UIPath动态操作控制

    如果放弃太早,你永远都不知道自己会错过什么. 一.浏览器 打开浏览器:OpenBrowser: 关闭浏览器:Close Tab.Close Application.Kill Process: 二. 鼠 ...

  2. C#winform中使用SQLite数据库

    公众号「DotNet学习交流」,分享学习DotNet的点滴. SQLite简介 SQLite是一种轻量级的关系型数据库管理系统(RDBMS),它以一个C库的形式提供.以下是SQLite数据库的一些关键 ...

  3. 主数据管理系统(MDM)集成方案

    在当今社会,数据已成为企业发展的宝贵财富.然而,大多数企业面临着数据散落在多个系统中.无法互相印证和共享的问题,导致数据使用效率低下.为解决这个问题,目前有两种典型途径:建设公司级系统或建立数据共享平 ...

  4. BI软件是什么?应用BI工具能给企业带来什么

    BI软件是指利用数据挖掘.分析和可视化等技术,将企业内部和外部数据转化为有价值的信息和洞察,以帮助企业支持业务决策和优化业务流程的工具和应用程序.常见的BI软件包括Datainside.QlikVie ...

  5. 有什么巨好用Excel数据分析技巧?

    当涉及Excel数据分析时,以下是一些非常实用的技巧和功能,供您参考.这里将为您提供关于数据整理.数据清洗.统计分析.可视化和高级分析等方面的技巧. 一.数据整理与清洗: 导入数据:使用 Excel ...

  6. Activity发送信息给Fragment

    在MainActivity中设置发送的信息,在fragment中接收, @Override public void onClick(View view) { switch (view.getId()) ...

  7. Cocos2d-js 游戏切后台和返回游戏,系统监听事件

    在日常游戏开发中,我们会发现,实时类操作的游戏,在模拟器中切后台,然后切回游戏,会出现很多异常. 很幸运,Cocos官方已经为我们预留了接口 1 LogicGame.addSystemListener ...

  8. MySQL运维6-Mycat垂直分库

    一.垂直分库场景 场景:在业务系统中,涉及一下表结构,但是由于用户与订单每天都会产生大量的数据,单台服务器的数据存储以及处理能力是有限的,可以对数据库表进行拆分,原有数据库如下 说明1:整个业务系统中 ...

  9. CatFly【汇编代码还原】

    CatFly[难度:1] 题目界面 下载附件,发现是dll文件,放到linux中运行一下,运行界面如图所示: 从上图中可以看到两处字符串,上面的字符串不断滚动,下方字符串在次数上不断累加,猜测上方字符 ...

  10. bash shell笔记整理——外部命令和内部命令区别

    linux命令的类别: 外部命令 内部命令 什么是内部命令 bash shell程序内部自带的命令. 什么是外部命令 不是bash shell内建命令,bash会根据用户给定的命令从PATH环境变量中 ...