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

标签 java maven encryption spring-3 jasypt

尝试使用 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

应用程序属性编码如下:

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

我的 spring 配置如下所示:

<?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>

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

关于如何解决这个问题有什么想法吗?

最佳答案

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

这些文件可以从 Oracle 的站点下载(从您下载 JDK 的同一页面)并根据略有不同的许可协议(protocol)进行分发,因为您必须确保您不是来自“禁止”的国家(伊朗,北卡罗来纳州)。韩国等)...

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

关于java - 加载应用程序属性时出现加密异常(Java jasypt 加密),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13244120/

相关文章:

java - Geotools lib 突然从存储库中消失

java - Maven 使用与系统不同的时区

security - 是否可以使用 64 位 I/O block 大小来实现 AES?

java - JPA @Column 注释 getter 不起作用

java - 如何使用widget.switch更改editText值Android

java - Jenkins + Maven 发布插件 : release:branch + Git - Unable to commit files

java - 加密文本文件以防止可读

encryption - 具有加密/密码保护的 SQLite

java - 聚合 + 多重性 UML 说明

java - 错误 RetroFit Begin ARray Object .IllegalStateException