About Druid Database password encryption process and problems

Source: Internet
Author: User
Tags decrypt

Recent projects need to be in the configuration of the database password encryption, the use of Ali's Druid to achieve, the process and issues to share with you.

The project is using Spring Plus jetty, the original database connection using Apache Dbcp:commons-dbcp2-2.1.1.jar+ojdbc6.jar

Configuration: <new class= "Com.alibaba.druid.pool.DruidDataSource";
             <set name= "Driverclassname" >ORACLE.JDBC.DRIVER.ORACLEDRIVER</SET>
             <set name= "url" >jdbc:derby:memory:spring-test;create=true </set>
             <set name= "username" >test123</Set>             
            < Set name= "password" >test123</Set>      
            <set name= "Validationquery" >select 1 from dual</set>            
         </new>

Change into Druid:druid-1.0.13.jar+ojdbc6.jar

Configuration: (Simply change the class to Com.alibaba.druid.pool.DruidDataSource)

<new class= "Com.alibaba.druid.pool.DruidDataSource" >
<set name= "Driverclassname" >oracle.jdbc.driver.OracleDriver</Set> (not even available, will be automatically identified according to the URL)
<set name= "url" >jdbc:derby:memory:spring-test;create=true</Set>
<set name= "username" >test123</Set>
<set name= "Password" >OkBVtGCZIhSXT7Fcg==</Set>
<set name= "Filters" >config</Set>
<set name= "ConnectionProperties" >config.decrypt=true</Set>
<set name= "Validationquery" >select 1 from dual</set>
<call name= "Init"/>
</New>

Explanation of the above configuration: Other parameter configuration is not detailed, key explanation database password encryption

1.password: Using commandsjava -cp druid-1.0.13.jar com.alibaba.druid.filter.config.ConfigTools you_password来生成密码

Each time you execute a generated cipher, it's not the same.

If you are using thedruid-1.0.31.jar会生成privateKey、passwordKey和publicKey,配置需改成

<set name= "Password" >OkBVtGCZIhSXT7Fcg==</Set><!--generated Passwordkey--
<set name= "Filters" >config</Set>
<set name= "ConnectionProperties" >config.decrypt=true; CONFIG.DECRYPT.KEY=DSDFGTGETGSD</Set> <!--generated-- publicKey (no change can also, with default)

2.filters: Configuring Monitoring

3.connectionproperties:config.decrypt=true prompting Druid Data source to decrypt the database password

4. <call name= "Init"/>: This method must be configured.

In the Https://github.com/alibaba/druid/tree/master download source project Import project, debug source found after the parameters can be received, but not to perform the decryption operation, has been error user name \ password is invalid, login is denied, Plus this method of configuration can walk through

Refer to https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98 for other related questions

Https://github.com/alibaba/druid/wiki/%E4%BD%BF%E7%94%A8ConfigFilter

After configuration, the error package Oracle.jdbc.driver is sealed, the database packet is encrypted, the general case is the jar package conflict.

Troubleshooting for a long time finally in a war package found Ojdbc7.jar, remove 7, finally can run normally.

About Druid Database password encryption process and problems

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.