1.在pom.xml文件中添加依赖
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>1.17</version>
</dependency>
github地址:https://github.com/ulisesbocchio/jasypt-spring-boot
2.在测试类中加密明文
import org.jasypt.util.text.BasicTextEncryptor;
import org.junit.Test;
public class TestYmlEncryption {
@Test
public void jasyptTest() {
BasicTextEncryptor encryptor = new BasicTextEncryptor();
// application.yml配置的jasypt.encryptor.password
encryptor.setPassword("MS");
// 对root进行加密操作
System.out.println(encryptor.encrypt("mq"));
// 进行解密操作
System.out.println(encryptor.decrypt("***"));
}
}
3.在application.yml中配置加密信息
jasypt:
encryptor:
password: MS
username: ENC(加密后秘钥)