使用Druid对数据库密码进行加密解密

1、进入到druid-1.0.31.jar下载的目录中,打开cmd控制台,输入以下命令:
java -cp druid-1.0.27.jar com.alibaba.druid.filter.config.ConfigTools your_password
eg:
java -cp druid-1.0.27.jar com.alibaba.druid.filter.config.ConfigTools 123456

执行后获得以下内容:

privateKey:MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAtSW2imSbuFV+ZrErmOQP+jQfoQtyTQ62VQIAEe+mCgelY3gexKFA8CDcbj2n9pujh79PjO0hg2NE/mASR75ROQIDAQABAkEAqKX237uxOpnl94elNk/GDERw2geFH/a9jEEzfX9nT1efzP6PiPwb4H82V6FRoWfCwSsmlbeSMb3/4LxqBlVZ8QIhAPkAUQ8EYBt953UVOS4JX42qzDDtmfOKV0oEcJ0oED6VAiEAuj0np7Q5BRHYPITPL4vylr4MgBjgqa1fXfqZ7NlLsxUCIAwW9diSz8/F5y0KIMKZdeg8+LkPcEAg4WgYmxcmUNOZAiAJfFfquMk2suP6oSEUYOJoPyHP3HSE7+mtlbgFUkQCyQIgZOUpQRGZ1CRCsRf+4yJmV4wtUrmz+YhBdT851lwuoCU=
publicKey:MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALUltopkm7hVfmaxK5jkD/o0H6ELck0OtlUCABHvpgoHpWN4HsShQPAg3G49p/abo4e/T4ztIYNjRP5gEke+UTkCAwEAAQ==
password:bN2OreHMM6RtqaK87h91p/Ea9fev0uhHoOxgmt1c/RNphVnblVkxa18GPp8Zr7W3v/XMETBTikm1MR30sbidrw==
2、在工程application.yml文件中,用生成的password覆盖原来的明文密码,同时在文件中添加如下配置:
spring.datasource.druid.publicKey=生成的publicKey
3、解密,在Druid中已经提供了解密的方法,只需要在配置文件中添加如下配置:
 filters: config,stat
      connection-properties: config.decrypt=true;config.decrypt.key=生成的publicKey     

完成以上配置即可实现Druid对数据密码的加密解密!

你可能感兴趣的:(Druid)