1.使用代码进行加密
import com.alibaba.druid.filter.config.ConfigTools; //不设置公钥会用默认的公钥 public class DruidUtil { public static void main(String[] args) throws Exception { String password = "eemwAzEGD3JANdct"; System.out.println(ConfigTools.encrypt(password)); } }
1.默认的公私钥
privateKey:
MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAlFtDQgbIOR+cvpSUMO7HSKzWhsP/VI1FACGspyd0QBkvYhBSBTrjwhxtOvnHFoKXzD1kAh9ZHhqdq00Mp+9a3wIDAQABAkBrAMwpAkVF1kQyvW2JQZ/hDjCI8TLnJCGBb8hco7tYQvVgJ
YSAyNBejkLP4zOubOEftYqEN6NB07kwo53uV675AiEA5Es8gI8blYg3K/54A7wjlNGjxegdBkaNkrKAel3Vp50CIQCmXHx1KHldQMaOVyh0Clw9viEBmMaxZOX4a7Z8841pqwIhAOMDEaHBLKvQLRS5UXxdTICCyrlUq+/+nm8ew3Vq87ddAiEApG1PGeEaK2Bln7Rnq
GHBD8mHB/P/lr/6SNH1eYSj5acCIAnhIJL7WiVdvoNse4CAzzW7arbV3WZcgLewOmQJ/GXR
publicKey:
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJRbQ0IGyDkfnL6UlDDux0is1obD/1SNRQAhrKcndEAZL2IQUgU648IcbTr5xxaCl8w9ZAIfWR4anatNDKfvWt8CAwEAAQ==
password:
Y3KoItiTinbXyGlVK/Nr7Zr8jNJT1icStrEWNA9LcqBHKwV0fqdbw0T8LCOZ18QX55rcNAKRbyjzpyKrr+QceQ==
2.使用命令行
使用druid-1.1.6.jar包中的ConfigTools工具类对您的数据库密码进行加密! 命令如下: java -cp druid-1.1.6.jar com.alibaba.druid.filter.config.ConfigTools 你的密码
3.SpringBoot使用配置
#public-key=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKHGwq7q2RmwuRgKxBypQHw0mYu4BQZ3eMsTrdK8E6igRcxsobUC7uT0SoxIjl1WveWniCASejoQtn/BY6hVKWsCAwEAAQ== # mysql #spring.datasource.druid.url=jdbc:mysql://192.168.230.130:3306/education_user?useUnicode=true&characterEncoding=utf-8&useSSL=false #spring.datasource.druid.username=education_user #spring.datasource.druid.password=Gm0Nx4AZ0qL1d+hWY7qx9H7MiKvaRWS9y13utBO933P7b9LIPef99/1hvGns2CHR9wUBQDFtnrssHl6FsJQoag== #spring.datasource.druid.filters=stat,wall,log4j,config #spring.datasource.druid.connection-properties=config.decrypt=true;config.decrypt.key=${public-key} #spring.datasource.druid.filter.config.enabled=true