- 引入依赖
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
- 加密
BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();
basicTextEncryptor.setPassword(salt);
String encStr = basicTextEncryptor.encrypt(value);
- yml
jasypt.encryptor.password=anxin
spring.datasource.username=ENC(M03mB3zzuFAp+PuU/Ab0cQ==)
- salt配置在环境变量
打开/etc/profile文件
vim /etc/profile
文件末尾插入
export JASYPT=anxin
编译
source /etc/profile
- 部署时配置salt
- -Djasypt.encryptor.password=anxin
- –jasypt.encryptor.password=anxin
- –jasypt.encryptor.password=${JASYPT}