Results 1 to 4 of 4

Thread: encrypt password with c3p0

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Posts
    7

    Default encrypt password with c3p0

    We have a requirement for all clear text passwords to be encrypted in the context.xml file. Has anyone done this with c3p0? I found an example on how to do it with dbcp but we are using c3p0 in our app.

    http://stackoverflow.com/questions/1...-resource-defi

    I know you can not extend ComboPooledDataSource as it is final but is there another way?

  2. #2

    Default Did you find the solution to extend ComboPooledDataSource

    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.


    Quote Originally Posted by tdelesio View Post
    We have a requirement for all clear text passwords to be encrypted in the context.xml file. Has anyone done this with c3p0? I found an example on how to do it with dbcp but we are using c3p0 in our app.

    http://stackoverflow.com/questions/1...-resource-defi

    I know you can not extend ComboPooledDataSource as it is final but is there another way?

  3. #3
    Join Date
    Nov 2007
    Posts
    7

    Default

    Quote Originally Posted by shoaibrazakhan View Post
    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" 		
    	/>

  4. #4
    Join Date
    Oct 2010
    Location
    FL, USA
    Posts
    13

    Default

    You can try define your c3p0 pool as Spring bean and set the password as encrypted value using the "${/decrypt/blah}" format, then in the same xml context file, you can define your own custom "org.springframework.beans.factory.config.Property PlaceholderConfigurer#convertPropertyValue" to check for "/decrypt/" prefix and decrypt "blah" value. Basically you are translating a encrypted "blah" value into an decrypted value for Spring to inject when creating your c3p0 pool instance.
    Last edited by saltnlight5; Jan 2nd, 2013 at 12:04 PM.
    Zemian Deng
    ---------------
    Follow my blog at http://saltnlight5.blogspot.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •