Java 无法使用jasypt加密属性文件中的用户名/密码
我正在使用Spring3.1和hibernate4开发项目 现在我想从属性文件中加密数据库的用户名、密码等敏感数据 以下是我遵循的步骤:(参考) 1.配置占位符:Java 无法使用jasypt加密属性文件中的用户名/密码,java,spring,hibernate,jasypt,Java,Spring,Hibernate,Jasypt,我正在使用Spring3.1和hibernate4开发项目 现在我想从属性文件中加密数据库的用户名、密码等敏感数据 以下是我遵循的步骤:(参考) 1.配置占位符: <bean id="propertyConfigurer" class="org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer"> <constructor-arg ref="configurationEncryptor
<bean id="propertyConfigurer" class="org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer">
<constructor-arg ref="configurationEncryptor" />
<property name="locations">
<list>
<value>/WEB-INF/classes/connection.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
5.connection.properties文件包含
data.user=ENC(VO0A3aXAu71CCgzGFa+nJO/7M/0b5MF2)
data.password=ENC(EogzgPllaXTDm7wq5kRp6uPmkWq6pmDV)
当我运行应用程序时,仍然会出现以下错误:
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "ENC(VO0A3aXAu71CCgzGFa+nJO/7M/0b5MF2)"
以下是我为将Spring应用程序与jasypt集成而提供的额外JAR:
commons-dbcp-1.1.jar
commons-lang-2.1.jar
commons-pool-1.2.jar
icu4j-3.4.4.jar
jasypt-1.9.0.jar
jasypt-1.9.0-lite.jar
jasypt-acegisecurity-1.9.0.jar
jasypt-hibernate4-1.9.0.jar
jasypt-spring3-1.9.0.jar
jasypt-spring31-1.9.0.jar
我是否遗漏了任何东西,或者是否存在任何jar兼容性问题?看起来不像是遗漏的jar问题。 Jasypt无法解密用户名/密码。 对于Spring 3.1,我建议使用以下配置:
<encryption:encryptable-property-placeholder encryptor="stringEnc" propertie-ref="dbProperties" ignore-unresolvable="true"/>
<encryption:string-encryptor id="stringEnc" algorithm="PBEWithMD5AndDES" password="MASTERPASSWORD" />
<bean id="dbProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location">
<value>/WEB-INF/classes/connection.properties</value>
</property>
</bean>
/WEB-INF/classes/connection.properties
看起来不像是丢失的jar问题。
Jasypt无法解密用户名/密码。
对于Spring 3.1,我建议使用以下配置:
<encryption:encryptable-property-placeholder encryptor="stringEnc" propertie-ref="dbProperties" ignore-unresolvable="true"/>
<encryption:string-encryptor id="stringEnc" algorithm="PBEWithMD5AndDES" password="MASTERPASSWORD" />
<bean id="dbProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location">
<value>/WEB-INF/classes/connection.properties</value>
</property>
</bean>
/WEB-INF/classes/connection.properties
commons-dbcp-1.1.jar
commons-lang-2.1.jar
commons-pool-1.2.jar
icu4j-3.4.4.jar
jasypt-1.9.0.jar
jasypt-1.9.0-lite.jar
jasypt-acegisecurity-1.9.0.jar
jasypt-hibernate4-1.9.0.jar
jasypt-spring3-1.9.0.jar
jasypt-spring31-1.9.0.jar
<encryption:encryptable-property-placeholder encryptor="stringEnc" propertie-ref="dbProperties" ignore-unresolvable="true"/>
<encryption:string-encryptor id="stringEnc" algorithm="PBEWithMD5AndDES" password="MASTERPASSWORD" />
<bean id="dbProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location">
<value>/WEB-INF/classes/connection.properties</value>
</property>
</bean>