如何在Spring Boot中配置数据库密码加密? · alibaba/druid Wiki · GitHub
使用ConfigFilter · alibaba/druid Wiki · GitHub
巧用Druid数据源实现数据库连接密码的加密解密功能
import com.alibaba.druid.filter.config.ConfigTools;
public class Testttt {
public static void main(String[] args) throws Exception {
String password = "123456";
System.out.println("明文密码: " + password);
String[] keyPair = ConfigTools.genKeyPair(512);
//私钥
String privateKey = keyPair[0];
System.out.println("privateKey:" + privateKey);
//公钥
String publicKey = keyPair[1];
System.out.println("publicKey:" + publicKey);
//用私钥加密后的密文
password = ConfigTools.encrypt(privateKey, password);
System.out.println("password:" + password);
String decryptPassword = ConfigTools.decrypt(publicKey, password);
System.out.println("解密后:" + decryptPassword);
}
}