1. 程式人生 > >springboot中數據庫配置加密

springboot中數據庫配置加密

springboot 加密

在springboot中,配置數據庫等信息時,用戶名和密碼明文顯示會大大降低安全性,在此介紹一種加密方式,簡單易用。

添加依賴:

<dependency>
   <groupId>com.github.ulisesbocchio</groupId>
   <artifactId>jasypt-spring-boot-starter</artifactId>
   <version>1.8</version>
</dependency>

在yml文件或properties文件中配置加密參數:

jasypt:
  encryptor:
    password: 123

得到加密後的密碼:

@Autowired
    StringEncryptor stringEncryptor;    @Test
    public void encryptPwd() {
        String result = stringEncryptor.encrypt("yourpassword");
        System.out.println(result); 
    }

將加密後的密碼配置在yml或properties文件中即可:

datasource:
    url: jdbc:mysql://網段/數據庫名
    username: 用戶名
    password: ENC(Ipjb1cUctOHmbt6a1qIUjw==) #Ipjb1cUctOHmbt6a1qIUjw==  就是加密後的密碼
    driverClassName: com.mysql.jdbc.Driver

springboot中數據庫配置加密