前言
数据库密码直接明文写在配置中,对安全来说,是一个很大的挑战。一旦密码泄漏,将会带来很大的安全隐患。尤其在一些企业对安全性要求很高,因此我们就考虑如何对密码进行加密。本文着重介绍Jasypt对SpringBoot配置文件加密。
引入maven
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
生成加密串
将连接数据库的用户名和密码进行加密
public static void main(String[] args) {
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
//加密所需的salt(盐)
textEncryptor.setPassword("Bt%XJ^n1j8mz");
//要加密的数据(数据库的用户名或密码)
String username = textEncryptor.encrypt("toutou");
String password = textEncryptor.encrypt("demo123456");
System.out.println("username:"&