The database is encrypted.
First, one of the most online tutorials, a better tutorial, as follows,
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 username/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 the URL Rewrite SetUrl (URL) */@SuppressWarnings ("All") public class Decryptdruidsource extends druiddatasource{@ overridepublic void Setusername (String username) {try {username = Configtools. Decrypt (username);} catch ( Exception e) {e. printstacktrace ();} Super.setusername (username);}}
Configuration of database connections in 3.spring-database.xml
<BeanId="DataSource"class="Com.heli.core.user.common.DecryptDruidSource" ><PropertyName="Driverclassname"Value="${driver}"/><PropertyName="url"Value="${url}"/><PropertyName="Username"Value="${username}"/><PropertyName="Password"Value="${password}"/><!--config.decrypt=true--<PropertyName="Filters"Value="Config"/><PropertyName="ConnectionProperties"Value="Config.decrypt=true"/><!--Initialize connection size--<PropertyName="InitialSize"Value="${initialsize}"/><!--connection pool maximum number of connections to use-<PropertyName="Maxactive"Value="${maxactive}"/><!--connection Pool maximum idle This parameter has been deprecated <property name= "maxidle" value= "${maxidle}" ></property>-<!--connection Pool min free--<PropertyName="Minidle"Value="${minidle}" ></Property><!--get connection Maximum wait time--<PropertyName="Maxwait"Value="${maxwait}" ></Property><PropertyName="Validationquery"Value="${validationquery}"/><PropertyName="Testwhileidle"Value="${testwhileidle}"/><PropertyName="Testonborrow"Value="${testonborrow}"/><PropertyName="Testonreturn"Value="${testonreturn}"/>< how long!--configuration interval to detect idle connections that need to be closed, in milliseconds-and<PropertyName="Timebetweenevictionrunsmillis"Value="${timebetweenevictionrunsmillis}"/><!--Configure the minimum time for a connection to survive in a pool, in milliseconds--<PropertyName="Minevictableidletimemillis"Value="${minevictableidletimemillis}"/><!--turn off long-unused connections--<!--open removeabandoned function--<PropertyName="Removeabandoned"Value="${removeabandoned}"/><!--1200 seconds, that is 20 minutes-- < property name="removeabandonedtimeout" value= "${remove Abandonedtimeout} "/> <!--off abanded connection when output error log- <property name=" Logaband oned " value=" ${logabandoned} "/></bean>
4. Database configuration file:
3.user.properties中#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
但是上面那个教程有个问题,在才cmd下的加密时一个随时在变的,我只有在工程里写下如下文件,才能进行加密以及解密
1 Packagetest;2 3 Importorg.junit.Test;4 5 ImportCom.alibaba.druid.filter.config.ConfigTools;6 7 Public classDecryptdruid {8 /**9 * Decrypt the textTen * @throwsException One */ A @Test - Public voidTestdecrypt ()throwsException { - //decryption theString word= "mmuctiwe+hmrbuyavqdozwhxsb+rjy/hibo08lsxlpj/ocvxrvckpwamgwekkapedylu8rgpoaqsjsny7xg+fq=="; -String Decryptword =Configtools.decrypt (word); - System.out.println (Decryptword); - } + /** - * Text is encrypted + * @throwsException A */ at @Test - Public voidTestencrypt ()throwsException - { - //Encrypt -String password = "xxxxxxx"; -String Encryptword =configtools.encrypt (password); in System.out.println (Encryptword); - to } +}
It's good to use the code above, or the code is wrong.
Druid Encryption and decryption tool for data sources