1.在pom.xml文件中添加依赖
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>1.17</version>
</dependency>
2.在测试类中加密明文
import org.jasypt.util.text.BasicTextEncryptor;
import org.junit.Test;
/**
* @author: 594781919@qq.com
* @date: 2018/4/24
*/
public class UtilTests {
@Test
public void jasyptTest() {
BasicTextEncryptor encryptor = new BasicTextEncryptor();
encryptor.setPassword("abc123");
System.out.println(encryptor.encrypt("root"));
System.out.println(encryptor.decrypt("ddc3gpYHXk8o2a9TSXh9Yg=="));
}
}
3.在application.yml中配置加密信息
server:
servlet:
context-path: /auth
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/springboot?useSSL=false&useUnicode=true&characterEncoding=utf-8
username: ENC(k4LGQOt0V9uQeB3i5EDiLw==)
password: ENC(k4LGQOt0V9uQeB3i5EDiLw==)
driver-class-name: com.mysql.jdbc.Driver
redis:
database: 0
host: 127.0.0.1
password:
timeout: 8000
port: 6379
jasypt:
encryptor:
password: abc123