Druid Implementing database Connection password encryption

Source: Internet
Author: User
Tags decrypt

jar Package version: Druid-1.0.13.jar

1. encrypt to encrypt user name and password under command

CMD command line execution java-cp d:/druid-1.0.13.jar com.alibaba.druid.filter.config.ConfigTools user name / Password

Get ciphertext :

f0psl0lzxh6cxzufideg+wvx045fse2vtup45g9hh2cjvqnmgggck5clznujor6tgwro44h74oxrbwudzwc8jg==

2. user name decryption:

Ackage Com.heli.core.user.common;import Com.alibaba.druid.filter.config.configtools;import com.alibaba.druid.pool.druiddatasource;/*** is used to decrypt the ciphertext in the configuration (the key configuration, where the decryption of the user name is Extended) the * Setusername (name) method corresponds to a property attribute in the XML , password default encryption does not need to be rewritten, * can also encrypt URL rewrite seturl (URL) */@SuppressWarnings ("all") the public class Decryptdruidsource extends druiddatasource{@Overridepublic void Setusername (String username) {try {username = Configtools.decrypt (username);} catch (Exception e) {e.printstacktrace ();} Super.setusername (username);}}

3. Configuration of database connections in spring-database.xml

<bean id= "DataSource"  class= "Com.heli.core.user.common.DecryptDruidSource" ><property  Name= "Driverclassname"  value= "${driver}"  /><property name= "url"  value= "${url}"   /><property name= "username"  value= "${username}"  /><property name= "password"  value= "${password}"  />        <!--  Config.decrypt=true -->   <property name= "Filters"  value= "config"  / >       <property name= "ConnectionProperties"  value= " Config.decrypt=true " />      <!--  Initialize connection size  -->< Property name= "InitialSize"  value= "${initialsize}"  /><!--  Connection pool max usage Connections  --> <property name= "maxactive"  value= "${maxactive}"  /><!--  Connection Pool Max idle   This parameter has been deprecated  <property name= "Maxidle"  value= "${maxidle}" ></property> --><!--  Connection pool min idle  --><property name= "Minidle"  value= "${minidle}" ></property><!--  Get connection Maximum wait time  --><property name= " Maxwait " value=" ${maxwait} "></property>          <property name= "Validationquery"  value= "${validationquery}"  />         <property name= "Testwhileidle"  value= "${testwhileidle}"  />         <property name= "Testonborrow"  value= "${testOnBorrow}"  />        <property name= "TestOnReturn"  value= "$ {Testonreturn} " />         <!--  configuration interval How often does a test Detects idle connections that need to be closed in milliseconds  -->        <property name= " Timebetweenevictionrunsmillis " vAlue= "${timebetweenevictionrunsmillis}"  />        <!--   Configure the minimum lifetime of a connection in a pool, in milliseconds  -->        <property name = "Minevictableidletimemillis"  value= "${minevictableidletimemillis}"  />          <!--  Close unused connections for a long time  -->         <!--  Open removeabandoned function  -->        <property  name= "removeabandoned"  value= "${removeabandoned}"  />         <!-- 1200 seconds, which means 20 minutes  -->        <property  name= "Removeabandonedtimeout"  value= "${removeabandonedtimeout}"  />         <!--  Output error log when abanded connection is closed  -->         <property nAme= "logabandoned"  value= "${logabandoned}"  /></bean> 

4. Database configuration file:

3.user.properties in #mysqlusername=f0psl0lzxh6cxzufideg+ wvx045fse2vtup45g9hh2cjvqnmgggck5clznujor6tgwro44h74oxrbwudzwc8jg==password=f0psl0lzxh6cxzufideg+ Wvx045fse2vtup45g9hh2cjvqnmgggck5clznujor6tgwro44h74oxrbwudzwc8jg==url=jdbc:mysql://192.168.1.194/user? characterencoding=utf-8driver=com.mysql.jdbc.driverinitialsize=5minidle=5maxactive=20maxwait= 60000timebetweenevictionrunsmillis=60000minevictableidletimemillis=30000validationquery=select 1testWhileIdle= truetestonborrow=truetestonreturn=truefilters=stat,log4jremoveabandoned=trueremoveabandonedtimeout= 1200logabandoned=true

Druid Implementing database Connection password encryption

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.