赞
踩
druid数据原密码加密
修改配置文件:
#修改密码:
spring.druid.password=H2gFHtRJ3D1EJgKNfOHeWg/DSZ5+l46YB2XaU0nbNQGpZgmzin60gX7cLpKeLChCAGP89LM0dDgH3KFlBjPplA==
#注掉
#spring.druid.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
=====以下为新增
#公钥
spring.druid.publicKey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJouXgKAFORj65od2bQYNavTZa7EQiB7jUfXUblsPyCRpVhYquVAeE3Kz1iujnl1zazAcNunQpIGXAZ8auaNUrsCAwEAAQ==
#Properties
spring.druid.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000;config.decrypt=true;publickey=${spring.druid.publicKey};password=${spring.druid.password}
spring.druid.filter.config.enabled=true
#密码工具类
spring.druid.passwordCallbackClassName=com.sinosoft.channel.common.configuration.DbPasswordCallback
-
- import com.alibaba.druid.filter.config.ConfigTools;
- import com.alibaba.druid.util.DruidPasswordCallback;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
-
- import java.util.Properties;
-
- //import org.apache.log4j.Logger;
-
- /**
- * @Description druid数据源配置回调函数
- */
- public class DbPasswordCallback extends DruidPasswordCallback {
-
- private static final Logger logger = LoggerFactory.getLogger(DbPasswordCallback.class);
-
- /**
- * @Description 数据库密码解密方法
- * @param properties
- */
- @Override
- public void setProperties(Properties properties) {
- super.setProperties(properties);
- String password = (String) properties.get("password");
- String publickey = (String) properties.get("publickey");
- try {
- String dbpassword = ConfigTools.decrypt(publickey, password);
- setPassword(dbpassword.toCharArray());
- } catch (Exception e) {
- logger.error("Druid ConfigTools.decrypt", e);
- }
-
- }
- }
生成密文和公钥方式
生成RSA密码:
找到druid jar所在路径
打开cmd
进入路径:
cd D:\work\maven\repository-1\com\alibaba\druid\1.0.19
执行命令:(红色部分为数据库密码)
java -cp .\druid-1.0.19.jar com.alibaba.druid.filter.config.Conf
igTools xxx
返回结果: privateKey 为私钥,publicKey:为公钥 password:为加密后的密码。
privateKey:MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAgz58uKq0OMnSLlj1Yn+JXDkil0QMrc8n73+otItnyDoMGvn/mgR/9eMqZvSZnyYzvR29gSFLZRlGpp+D6Du5FQIDAQABAkBQb6206DpIS7kbWr4ZvhyLfyDqIHS82aeaK11UOdRDbBu1+Xh1HPYCjLlyLw1PE9eakdk5DAlIuClI4YAolUjJAiEA28pyZfJdU3FMFvPLvRxAccoRQnicAOGd9CzjCAQskscCIQCY3aHu1wzqAbYDYfktfik1/xKgQwjaDcqSJAHLygU5QwIgcBLZJpbhc80P6ZxDRZkEW4GYL3bkxaZGLt48njfSqr0CIA7rMm6Y1k3QNO9HlIX4FhWK+0pgwHBngCmbEgHNiYz5AiB+tPgBOpLEfu+MSM8G0NXlEd8ejRT1HGTvzrS+TN/8dw==
publicKey:MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIM+fLiqtDjJ0i5Y9WJ/iVw5IpdEDK3PJ+9/qLSLZ8g6DBr5/5oEf/XjKmb0mZ8mM70dvYEhS2UZRqafg+g7uRUCAwEAAQ==
password:czWM6yj+YHeCFQqgxzfDhrnnXq25YvnaZZCyKtsRNiq3ACU+wDNxPJ55rl/dmruWmFsx7eA36qDarUHri0YcHw==
将 publicKey 赋给 spring.druid.publicKey 将 password 赋给spring.druid.password
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。