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

Chi*_*lax 4 java encryption jasypt maven spring-3

尝试使用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
Run Code Online (Sandbox Code Playgroud)

应用程序属性的编码如下:

app.check.url=ENC(sCO3322RNYdt3wPfO04GoaN9PijwJzUcn9rb4ggHymA\=)
Run Code Online (Sandbox Code Playgroud)

我的弹簧配置如下所示:

<?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>
Run Code Online (Sandbox Code Playgroud)

我有jdk 1.7,它有加密所需的JCE文件.

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

Dan*_*dez 9

你的问题不在于你没有JCE.你做.但是从您的配置中,您使用的是TripleDES算法,这需要安装JCE"Unlimited Strength Jurisdiction Policy files",如错误所示.

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

请参阅Jasypt常见问题解答中的这个问题:http://www.jasypt.org/faq.html#no-unlimited-strength

  • 哦,在StackOverflow编辑器删除这篇帖子之前我解决了你的问题而没有提到我是该事的作者:我是jasypt的作者.现在你知道了 ;-) (5认同)

Ami*_*Ami 5

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

  1. 请点击此链接并解决您的错误.[或]
    2. org.jasypt.exceptions.EncryptionOperationNotPossibleException