在配置文件中会有些敏感信息,比如数据库账号和密码,如果使用明文是不安全的,这时候我们可以用jasypt对这些信息进行加密。
文章目录- 1.引入依赖:
- 2.加密
- 3.用密文替换明文
- 4.配置jaspyt
- 5.JVM启动参数中设置密钥
com.github.ulisesbocchio jasypt-spring-boot-starter 2.1.1
注意版本,有些版本无法解密。
2.加密public class EncryptConfigUtil {
public static void main(String[] args) {
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
//加密所需的salt
textEncryptor.setPassword("12321");
//要加密的数据(数据库的用户名或密码)
String username = textEncryptor.encrypt("root");
String password = textEncryptor.encrypt("123");
System.out.println("username:"+username);
System.out.println("password:"+password);
}
}
3.用密文替换明文
4.配置jaspyt
也可以配置加密算法等,这里不再赘述



