Druid数据库密码加密
背景
数据库密码直接写在配置中,对安全来说,是一个很大的挑战。Druid为此提供一种数据库密码加密的手段ConfigFilter。
druid版本为1.1.18。
加密
1.项目中引入依赖
<dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.18</version> </dependency>
2.打开cmd命令窗口,进入druid的jar所在位置
3.执行命令
java -cp druid-1.1.18.jar com.alibaba.druid.filter.config.ConfigTools 数据库密码
4.配置数据源,Druid数据源需要对数据库密码进行解密
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="filters" value="config" /> <property name="connectionProperties" value="config.decrypt=true;config.decrypt.key=${jdbc.publickey}" /> </bean>
5.application.properties配置数据库连接属性
# Spring Datasource Settingsjdbc.type=mysql jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false jdbc.username=root jdbc.password=fy5sM+1Vo/2NZAN9RxmLVIsq/44Yil69T3Ut371h5AvGvnIUSyf6A7TKrrtkaUMa5Yp/VH+kwic+PF3UhWODyA== jdbc.publickey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAI7sCmm9z5XNGH4tBYtD01Zz3gbdmcNCkrN5RBkV3iBNiHkyBYeQ/ew3Ca2576TvTlxW+iDt1qZSKGZdqEb0cg8CAwEAAQ== # pool settings jdbc.pool.init=1 jdbc.pool.minIdle=3 jdbc.pool.maxActive=20 jdbc.testSql=SELECT ‘x‘
相关推荐
杜鲁门 2020-11-05
yunzhonmghe 2020-08-07
Rain 2020-06-25
咻pur慢 2020-06-18
thunderstorm 2020-06-06
仰起嘴角 2020-05-27
吾日五省我身 2020-05-12
baobaozai 2020-04-30
GechangLiu 2020-04-26
heywakeup 2020-04-23
jaylong 2020-03-23
shisongsong 2020-03-11
chognzhihongseu 2020-03-06
bluetears 2020-03-03
84593973 2020-03-03
Kele0 2020-02-23
nan00zzu 2020-02-11
suixinsuoyu 2019-12-28