首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Spring Boot集成Jasypt异常DecryptionException

Spring Boot集成Jasypt异常DecryptionException

作者头像
程序新视界
发布2021-12-07 15:08:54
发布2021-12-07 15:08:54
1.7K0
举报
文章被收录于专栏:丑胖侠丑胖侠

在Spring Boot项目中对Jasypt进行集成,当生成密码之后,启动程序抛如下异常:

代码语言:javascript
复制
com.ulisesbocchio.jasyptspringboot.exception.DecryptionException: Unable to decrypt。

完整异常信息如下:

代码语言:javascript
复制
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的加密算法是有所区别的,默认采用的加密算法与你生成密码的加密算法是否一致。如果不一致,那肯定无法进行解密;
  • 第三,JDK没有安装不限长度的JCE版本(Unlimited Strength Java Cryptography Extension)。这种情况需要检查一下本地$JAVA_HOME/jre/lib/security目录下是否包含local_policy.jar和US_export_policy.jar量个jar包。如果没有,则进行添加。

第三种情况,所需的jar包可通过Oracle官网进行下载,下载地址:http://blog.didispace.com/spring-boot-learning-2x/

博主简介:《SpringBoot技术内幕》技术图书作者,酷爱钻研技术,写技术干货文章。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021/09/30 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档