简体   繁体   English

EncryptionOperationNotPossibleException在集成测试中但不在应用程序中

[英]EncryptionOperationNotPossibleException in integration tests but not in application

I am using Jasypt with Bouncycastle in my Spring Boot application. 我在Spring Boot应用程序中使用Jasypt和Bouncycastle。 I can run my application fine and encrypted stuff gets added in the database. 我可以运行我的应用程序,并在数据库中添加加密的东西。

However, when running the unit tests, I get: 但是,在运行单元测试时,我得到:

org.jasypt.exceptions.EncryptionOperationNotPossibleException: Encryption raised an exception. org.jasypt.exceptions.EncryptionOperationNotPossibleException:加密引发了异常。 A possible cause is you are using strong encryption algorithms and you have not installed the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files in this Java Virtual Machine 可能的原因是您使用的是强加密算法,并且尚未在此Java虚拟机中安装Java Cryptography Extension(JCE)Unlimited Strength Jurisdiction Policy Files

Why does it work on my application and not the integration test (loads the same spring configuration as the application)? 为什么它适用于我的应用程序而不是集成测试(加载与应用程序相同的弹簧配置)? I am running both from IntelliJ IDEA using a standard Oracle Java 1.8.0_66. 我使用标准的Oracle Java 1.8.0_66从IntelliJ IDEA运行。

I am using the PBEWithSHA256And256BitAES-CBC-BC algo. 我正在使用PBEWithSHA256And256BitAES-CBC-BC算法。

Java comes with a default maximum strength of 128 bits. Java的默认最大强度为128位。

What you need is a set of files called Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files and is currently available at the Java SE download page . 您需要的是一组名为Java Cryptography Extension(JCE)Unlimited Strength Jurisdiction Policy Files的文件 ,目前可从Java SE下载页面获得 This zip file contains a couple of policy jars, which you need copy over the top of the ones already in the {java.home}/jre/lib/security directory of your JRE. 此zip文件包含几个策略jar,您需要将其复制到JRE的{java.home} / jre / lib / security目录中的那些策略jar的顶部。

This will let you change the key strength above 128 bits 这样可以将密钥强度更改为128位以上

UPDATE UPDATE

For Java 8, it will depend on the classpath. 对于Java 8,它将取决于类路径。 If one of the JCE jars ( local_policy.jar or US_export_policy.jar ) is present, then JCE unlimited cryptography is enabled. 如果存在其中一个JCE jar( local_policy.jarUS_export_policy.jar ),则启用JCE无限加密。 Maybe the Spring Boot application has this dependency fulfilled, but your tests not. 也许Spring Boot应用程序已满足此依赖性,但您的测试没有。

The JCE jars for Java 8 can be found here 可以在这里找到JCE Jars for Java 8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM