Jasypt 即Java Simplified Encryption
1引入依赖 <!--ENC加密解密--> <dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>2.1.1</version> </dependency> 2.生成密文 public static void main(String[] args) { BasicTextEncryptor textEncryptor = new BasicTextEncryptor(); //加密所需的salt(盐) textEncryptor.setPassword("you salt"); //要加密的数据(数据库的用户名或密码) String username = textEncryptor.encrypt("root"); String password = textEncryptor.encrypt("root"); System.out.println("username:"+username); System.out.println("password:"+password); } 3.配置加密 把生成的密文已ENC(密文)的方式写入配置文件jasypt.encryptor.password=you salt#你在设置密码时候配置得盐可参考博客
SpringBoot使用jasypt加解密密码 - 自行车上的程序员 - 博客园