1
我正在使用Spring3.1和hibernate4開發項目。無法使用jasypt加密屬性文件中的用戶名/密碼
現在我想從屬性文件中加密敏感數據,如用戶名,數據庫密碼。
下面是我遵循以下步驟:(REF http://www.jasypt.org/spring31.html)
1.Configuring佔位符:
<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>
2.配置用於加密
<bean id="encryptorConfig" class="org.jasypt.encryption.pbe.config.SimplePBEConfig">
<property name="algorithm" value="PBEWithMD5AndDES" />
<property name="password" value="MASTERPASSWORD" />
</bean>
<bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
<property name="config" ref="encryptorConfig" />
</bean>
3.Database連接
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${data.driver}"/>
<property name="url" value="${data.url}"/>
<property name="username" value="${data.user}"/>
<property name="password" value="${data.password}"/>
</bean>
使用jasypt通過命令個
4.Generated加密值:
encrypt input="MY_DATABASE_PASSWORD" password="MASTERPASSWORD" algorithm="PBEWithMD5ANDDES"
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集成在一起的額外的罐子:
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兼容性問題?