springboot对数据库密码加密
程序员文章站
2022-07-05 11:37:41
对数据库密码进行加密public class DataPassword { public static void main(String[] args) throws Exception { //密码明文 String password = "123456"; System.out.println("明文密码: " + password); String[] keyPair = ConfigTools.genKeyPair(512);...
使用com.alibaba.druid.filter.config.ConfigTools生成公私钥和密码
public class DataPassword {
public static void main(String[] args) throws Exception {
//密码明文
String password = "123456";
System.out.println("明文密码: " + password);
String[] keyPair = ConfigTools.genKeyPair(512);
//私钥
String privateKey = keyPair[0];
//公钥
String publicKey = keyPair[1];
//用私钥加密后的密文
password = ConfigTools.encrypt(privateKey, password);
System.out.println("privateKey:" + privateKey);
System.out.println("publicKey:" + publicKey);
System.out.println("password:" + password);
String decryptPassword = ConfigTools.decrypt(publicKey, password);
System.out.println("解密后:" + decryptPassword);
}
}
配置文件配置
pkg.datasource.password=加密后的密码
pkg.datasource.publicKey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJRtLhqdJ+oFUWz/H/KMHYcJJkPg/VRV0QcLq7EBVeggQaNPhRQqLwtseiKl0XbUhSlnpyiOeJ+7pHe8M770ZzECAwEAAQ==
spring.datasource.druid.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000;config.decrypt=true;config.decrypt.key=@pkg.datasource.publicKey@
本文地址:https://blog.csdn.net/weixin_44859876/article/details/110236761
上一篇: 大数据面试题总结
下一篇: iOS之2016面试题一