
Originally Posted by
shoaibrazakhan
Hi,
I'm facing the same issue. I'm trying to encrypt the password by overriding ComboPooledDataSource so that i can read it from a property file where its encrypted.
Kindly suggest if you have a solution for the same.
I wrapped the c3p0 datasource with my own encrypted one.
Code:
public class EncryptedDataSource implements PooledDataSource, Serializable, Referenceable {
private ComboPooledDataSource dataSource;
private String decrypt(String encrypted) {
try {
Cipher cipher = Cipher.getInstance(EncryptionConstants.algorithm);
cipher.init(Cipher.DECRYPT_MODE, EncryptionConstants.key);
return new String(cipher.doFinal(Base64.decodeBase64(encrypted)));
}
catch(Exception e) {
e.printStackTrace();
return null;
}
}
public void setUser(String user) {
dataSource.setUser(decrypt(user));
}
public void setPassword(String password) {
dataSource.setPassword(decrypt(password));
}
.....
Code:
<Resource
acquireIncrement="5"
auth="Container"
scope="Shareable"
name="jdbc/com/iDB"
type="com.ecom.framework.EncryptedDataSource"
driverClass="com.ibm.db2.jcc.DB2Driver"
factory="org.apache.naming.factory.BeanFactory"
jdbcUrl="jdbc:db2://qual:60000/db"
maxIdleTime="10" initialPoolSize="5" maxPoolSize="20" minPoolSize="5"
user="encrypted-user"
password="encrypted-pass"
/>