[問題] hibernate+jasypt在cfg.xml加密
我想在hibernate.cfg.xml的password進行加密
但是使用jasypt api後出現問題
錯誤訊息Could not obtain connection to query metadata :
User 's password is not correct
for the database server.
hibernate.cfg.xml的password從ENC(wxaBcN45KWo+65oABXmGBQ==)
改回原來未加密的password可以連線成功
加密後的字串也沒打錯問題
因為手動載入也可以連線成功
//手動載入加密字串程式片段
...
BasicTextEncryptor bte = new BasicTextEncryptor();
bte.setPassword("common");
confAffil.configure("informixAffil.cfg.xml");
//加密字串decode後 載入
confAffil.setProperty("hibernate.connection.password",
bte.decrypt("wxaBcN45KWo+65oABXmGBQ=="));
...
我看官網說明
Hibernate is told about which is the encryptor object
to be used for decrypting the encrypted parameters.
This encryptor object should have been registered beforehand
as a Hibernate Encryptor,
as explained in the 'Transparent data encryption' section.
但是我的程式是不是jasypt api的使用步驟有問題?
希望能給些意見
MainSession.java
public class MainSession {
...
//產生hibernate session
static {
try {
Configuration confAffil = new Configuration();
/*
*以下為jasypt的使用步驟
*/
StandardPBEStringEncryptor strongEncryptor
= new StandardPBEStringEncryptor();
strongEncryptor.setPassword("common");
HibernatePBEEncryptorRegistry registry
= HibernatePBEEncryptorRegistry.getInstance();
registry.registerPBEStringEncryptor(
"configurationHibernateEncryptor",strongEncryptor);
//load cfg
confAffil.configure("hibernate.cfg.xml");
serviceRegistry1 = new ServiceRegistryBuilder()
.applySettings(confAffil.getProperties()).buildServiceRegistry();
factoryAffil =
confAffil.buildSessionFactory(serviceRegistry1);
}catch (Throwable ex) {
System.err.println("Failed to create session." + ex);
throw new ExceptionInInitializerError(ex);
}
}
...
}
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"" rel="nofollow">http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory >
<property name=" hibernate.transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="connection.provider_class">
org.jasypt.hibernate4.connectionprovider.
EncryptedPasswordDriverManagerConnectionProvider
</property>
<property name="connection.encryptor_registered_name">
configurationHibernateEncryptor
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">
ENC(wxaBcN45KWo+65oABXmGBQ==)</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost/reportsdb;</property>
<property name="hibernate.connection.username">user</property>
<mapping resource="Amsspf1.hbm.xml"/>
</session-factory>
</hibernate-configuration>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.250.164.183
→
02/07 00:38, , 1F
02/07 00:38, 1F