加载应用程序属性时加密异常(Java jasypt 加密)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13244120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 12:00:25  来源:igfitidea点击:

Encryption Exception while loading application properties ( Java jasypt encryption)

javamavenencryptionspring-3jasypt

提问by Chillax

When trying to install a module using Maven, it throws up the following error:

尝试使用 Maven 安装模块时,会引发以下错误:

org.jasypt.exceptions.EncryptionOperationNotPossibleException:
Encryption raised an exception.
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

The application properties are encoded like this:

应用程序属性编码如下:

app.check.url=ENC(sCO3322RNYdt3wPfO04GoaN9PijwJzUcn9rb4ggHymA\=)

And my spring configuration looks like this:

我的弹簧配置如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:p="http://www.springframework.org/schema/p"
   xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="placeholderConfig" class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer">
    <constructor-arg ref="configurationEncryptor"/>
    <property name="ignoreResourceNotFound">
        <value>true</value>
    </property>
    <property name="ignoreUnresolvablePlaceholders">
        <value>false</value>
    </property>
    <property name="locations">
        <list>
            <!-- These always come from the file system in ./conf/appCtx -->
            <value>file:../application.properties</value>
        </list>
    </property>
    <property name="systemPropertiesModeName">
        <value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
    </property>
</bean>
<bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
    <property name="config" ref="environmentVariablesConfiguration"/>
</bean>
<bean id="environmentVariablesConfiguration"
      class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
    <property name="algorithm" value="PBEWithMD5AndTripleDES"/>
    <property name="passwordEnvName" value="APP_ENCRYPTION_PASSWORD"/>
</bean>

And I have jdk 1.7 which does have the necessary JCE files for the encryption.

我有 jdk 1.7,它确实有加密所需的 JCE 文件。

Any ideas on how to resolve this issue?

有关如何解决此问题的任何想法?

回答by Daniel Fernández

Your problem is not that you don't have the JCE. You do. But from your configuration, you are using a TripleDES algorithm and this requires installing the JCE "Unlimited Strength Jurisdiction Policy files", as the error says.

您的问题不在于您没有 JCE。你做。但是从您的配置来看,您使用的是 TripleDES 算法,这需要安装 JCE“无限强度管辖权策略文件”,如错误所述。

These files can be downloaded from Oracle's site (from the same page you download the JDK) and are distributed under a sligthly different license agreement, because you have to assure you are not from a "forbidden" country (Iran, N.Korea, etc)...

这些文件可以从 Oracle 的站点(从您下载 JDK 的同一页面)下载,并根据略有不同的许可协议分发,因为您必须确保您不是来自“被禁止的”国家(伊朗、朝鲜等) )...

See this question at the Jasypt FAQ: http://www.jasypt.org/faq.html#no-unlimited-strength

在 Jasypt 常见问题解答中看到这个问题:http: //www.jasypt.org/faq.html#no-unlimited-strength

回答by Ami

you did not install jce,by default present in lib\security.But its not accessed or used.please download jce files and overwrite the existing files.see your error itself you have not installed the Java Cryptography Extension (JCE)

您没有安装 jce,默认情况下存在于lib\security. 但它没有被访问或使用。请下载 jce 文件并覆盖现有文件。查看您的错误本身you have not installed the Java Cryptography Extension (JCE)

  1. Follow this linkand resolved your error. [or]
    2.org.jasypt.exceptions.EncryptionOperationNotPossibleException
  1. 按照此链接并解决您的错误。[或]
    2. org.jasypt.exceptions.EncryptionOperationNotPossibleException