项目环境
- springboot系列项目
- maven依赖管理
- 任意配置中心(apollo/配置文件/k8s ConfigMap Secrets)
项目代码添加依赖
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>${version}</version>
</dependency>
配置文件添加盐值
jasypt.encryptor.password = password
加密参数生成
//即为jasypt加密时使用的密码 jasypt.encryptor.password=test
private static final String soltPassWord = "test";
private static final String dbPassWord = "123456";
//即为参数配置时加密的密码 例如 db.password= ENC(ab/quILuP+CtWffG+lJyHQ==)
private static final String encPassword = "ab/quILuP+CtWffG+lJyHQ==";
public static void main(String[] args) {
// 加密时使用的密码
BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();
basicTextEncryptor.setPassword(soltPassWord);
String encrypt = basicTextEncryptor.encrypt(dbPassWord);
System.out.println("加密后的:"+encrypt);
BasicTextEncryptor basicTextEncryptor1 = new BasicTextEncryptor();
basicTextEncryptor1.setPassword(soltPassWord);
String decrypt = basicTextEncryptor1.decrypt(encPassword);
System.out.println("解密后的:"+decrypt);
}
加密参数值填写
#自定义前后缀
#jasypt.encryptor.property.prefix=ENC@[
#jasypt.encryptor.property.suffix=]
db.password= ENC(8dcdhff0dffdj)
参考资料
标签:加密,String,配置文件,jasypt,服务项目,参数,static,password From: https://www.cnblogs.com/BitX/p/18303240