SpringBoot Druid数据库密码加密

废话不多说,直接贴代码,毕竟搜这个的就是想知道怎么搞。

1. 依赖

        
            com.alibaba
            druid-spring-boot-starter
            1.1.18
        
       

2. 代码

  此类将输出三个参数,需要将输出的信息填入对应的配置,具体解释如下:

  • yourPassword + privateKey = encryptedPassword
  • encryptedPassword + publicKey = yourPassword
package net.mshome.twisted.tmall;

import com.alibaba.druid.filter.config.ConfigTools;
import org.junit.Test;

/**
 * @author [email protected]
 * @date 2019/9/1
 * @description druid密码加密
 */
public class DruidTest {

    @Test
    public void generateEncryptPasswordTest() throws Exception {
        String password = "your password here";
        ConfigTools.main(new String[]{password});
    }

}

 

3. 配置

spring:
  datasource:
    druid:
      url: jdbc:mysql://127.0.0.1:3306/tmall?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf8&autoReconnect=true
      username: tmall
      password: OwikKIgJr19o4kD/vGjwftCuBw38Ykj0uc7/L3vIzo2fel6ncFPjxP2NI6c50lfkAxk4mvU8grPRK1e+uuoVDw==
      public-key: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKmZEOoiXoua+jIUht/oYTDrZ4YKNbQhQkCM//gAy+zgaEVFdc6B83Honl1vGnv1FxHndX8oRQI1grK8rT/ClWkCAwEAAQ==
      filter:
        config:
          enabled: true
      connect-properties:
        config.decrypt: true
        config.decrypt.key: ${spring.datasource.druid.public-key}

 

你可能感兴趣的:(spring,database)