当前位置:   article > 正文

springboot中 druid数据源密码加密_passwordcallbackclassname

passwordcallbackclassname

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

  1. import com.alibaba.druid.filter.config.ConfigTools;
  2. import com.alibaba.druid.util.DruidPasswordCallback;
  3. import org.slf4j.Logger;
  4. import org.slf4j.LoggerFactory;
  5. import java.util.Properties;
  6. //import org.apache.log4j.Logger;
  7. /**
  8. * @Description druid数据源配置回调函数
  9. */
  10. public class DbPasswordCallback extends DruidPasswordCallback {
  11. private static final Logger logger = LoggerFactory.getLogger(DbPasswordCallback.class);
  12. /**
  13. * @Description 数据库密码解密方法
  14. * @param properties
  15. */
  16. @Override
  17. public void setProperties(Properties properties) {
  18. super.setProperties(properties);
  19. String password = (String) properties.get("password");
  20. String publickey = (String) properties.get("publickey");
  21. try {
  22. String dbpassword = ConfigTools.decrypt(publickey, password);
  23. setPassword(dbpassword.toCharArray());
  24. } catch (Exception e) {
  25. logger.error("Druid ConfigTools.decrypt", e);
  26. }
  27. }
  28. }

 


生成密文和公钥方式

生成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  

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/844084
推荐阅读
相关标签
  

闽ICP备14008679号