brettwooldridge / HikariCP

光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Apache License 2.0
19.87k stars 2.92k forks source link

Connection string password encryption in non-spring environment #359

Closed dentalpolitics closed 9 years ago

dentalpolitics commented 9 years ago

Hi, I noticed that the new hibernate-hikaricp connection provider doesn't seem to provide any support for Jasypt encryption. I managed to make hikaricp to work with a jasypt encrypted password through the jasypt-spring-boot-starter package but I also have non-spring applications and I couldn't find an encryption solution for those. Did I miss anything ? Looks like EncryptedDriverManagerConnectionProviderImpl from the jasypt-hibernate4-ext package provides such on-the-fly decryption concept. In the same way, would it be possible to integrate a jasypt decryptor in hikaricp's connection provider ? best regards kbjp

dentalpolitics commented 9 years ago

Just in case someone else is scouring the internet for a solution, here is a work-around for non-spring apps: 1) in hibernate.cfg.xml, put:

ENC([encrypted password here])

2) when initializing the session factory: StandardPBEStringEncryptor strongEncryptor = new StandardPBEStringEncryptor(); strongEncryptor.setAlgorithm("PBEWithMD5AndDES"); strongEncryptor.setPassword([encryption key here]); Configuration cfg = new Configuration().configure("/hibernate.cfg.xml"); EncryptableProperties props = new EncryptableProperties(cfg.getProperties(),strongEncryptor); cfg.setProperty("hibernate.connection.password",props.getProperty("hibernate.connection.password")); factory = cfg.addAnnotatedClass(HibUser.class).buildSessionFactory();