druid加密数据库密码,springboot项目

网上很多druid加密数据库密码真的非常繁琐,代码写的又难看死了,为了少给大家走弯路就随便写个博客吧,很简单的步骤,其实只要2步就可以解决加密问题,也不需要把公钥展示给任何人看

1、先写一个main函数通过druid提供的方法得到一个密文,私钥和公钥可以不要,也没必要

public static void main(String[] args){
   //加密
   try {
       String miwenofter = ConfigTools.encrypt("fjapp");
      System.out.println("加密后"+miwenofter);
   } catch (Exception e) {
      e.printStackTrace();
   }
   //解密
   try {
   String mingwen = ConfigTools.decrypt("TrI3cU/9qCEI872nH7wVjsxpRQimE4BgEZXTORoXre9FTzLV+Qtlyti3HYdA/fITeuBO8R4q4keGAPDobdC3uA==");
      System.out.println("解密后:"+mingwen);
   } catch (Exception e) {
      e.printStackTrace();
   }
}

2、在application.yml 添加两行代码即可(最重要的一步也是最后一步,)

spring:
  datasource:
    druid:
      filters: config,wall,stat
      connectionProperties: druid.stat.slowSqlMillis=200;druid.stat.logSlowSql=true;config.decrypt=true

实际就是添加1、spring.datasource.druid.filters = config,wall,stat

                      2、spring.datasource.druid.connectionProperties=druid.stat.slowSqlMillis=200;druid.stat.logSlowSql=true;config.decrypt=true

本人的yml配置文件:

spring:
  application:
    name: ylzinfo-cloud-app-lzf
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8
    default-property-inclusion: non_null
  decryptKey: test

  datasource:
    name: test
    url: jdbc:oracle:thin:@192.168.44.89:2521/sdsd
    username: dbAcount
    password: mWqOPO06wedwedwehgevwhIMsm1/yVJ3TIFmgcpHitf1ygL8J3kwXlZtVpdd9vhOCRCzaZK08OEAdYZREzLY3LrvE+sVbmUkoOKw==
    druid:
      filters: config,wall,stat
      connectionProperties: druid.stat.slowSqlMillis=200;druid.stat.logSlowSql=true;config.decrypt=true

如果配置文件不是application.yml,按照原理来都是一样,配置文件都是千篇一律 主要就是

1、spring.datasource.druid.filters = config,wall,stat

 2、spring.datasource.druid.connectionProperties=druid.stat.slowSqlMillis=200;druid.stat.logSlowSql=true;config.decrypt=true这两行代码

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值