Spring boot配置文件加密
JAR包
<!-- 配置文件加密 -->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>1.16</version>
</dependency>
盐值 jasPassword 加在配置文件中
jasypt:
encryptor:
password: ******
Jasypt配置文件密码加密解密工具类
package com.deloitte.pms.performance.provider.utils;
import org.jasypt.util.text.BasicTextEncryptor;
public class JasyptUtil {
public static String encrypt(String password, String jasPassword) {
BasicTextEncryptor encryptor = new BasicTextEncryptor();
encryptor.setPassword(jasPassword);
return encryptor.encrypt(password);
}
public static String decrypt(String password, String jasPassword) {
BasicTextEncryptor encryptor = new BasicTextEncryptor();
encryptor.setPassword(jasPassword);
return encryptor.decrypt(password);
}
}