前言
在SpringBoot项目开发中都需要把url、username、password等信息加数据库连接配置文件中,那么如果把明文账号密码直接写在配置文件中,会有很大的风险,一旦泄露对数据库数据安全会造成很大影响,如何对账号密码进行加密?
正文
配置文件中需加以下配置
#spring配置
spring:
#数据源配置
datasource:
url:jdbc:mysql://xxx
username:xxx
password:xxx(加密后的密文)
publickey:xxx(生成的公钥)
#druid配置,SpringBoot默认是不注入不了这些属性值的
druid:
#其余配置省略,如有需要请查阅相关文档
connectionProperties:config.decrypt=true;config.decrypt.key=$(publickey)
filter:
config:
enabled:true
公钥私钥和密码加密工具执行命令如下
java -cp druid-1.1.xx.jar com.alibaba.druid.filter.config.ConfigTools password(需要加密的密码)