springboot 整合druid數(shù)據(jù)庫密碼加密功能的實現(xiàn)代碼
在之前給大家介紹過Springboot Druid 自定義加密數(shù)據(jù)庫密碼的幾種方案,感興趣的朋友可以點擊查看下,今天通過本文給大家介紹springboot 整合druid數(shù)據(jù)庫密碼加密功能,具體內(nèi)容如下所示:
1.依賴引入
<dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.21</version> </dependency>
2.密碼加密處理
public static void main(String[] args) throws Exception { String password = "Aq6vD!puWbk"; 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); }
3.yml配置文件修改
connectionProperties需要注意,其他版本有connection-properties和connect-properties,注意區(qū)分
datasource: type: com.alibaba.druid.pool.DruidDataSource # 特別注意:java 9以后需要將com.mysql.jdbc.Driver 改為 com.mysql.cj.jdbc.Driver即可 # 否則報錯:Loading class `com.mysql.jdbc.Driver'. This is deprecated. driver-class-name: com.mysql.cj.jdbc.Driver druid: #基本屬性 url: jdbc:mysql://1******:3306/**?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai username: admin password: Qh0VAjlS/LVbsAFSAFsdf24jJ7rggMNsnvJex3x1mkUKxPd2bofuAR6DtjCV20M4n2DWc5SLZmkzgjvG3Elx1g== #此處需要注意,其他版本有connection-properties和connect-properties,注意區(qū)分 connectionProperties: config.decrypt=true;config.decrypt.key=${publicKey}; filter: config: enabled: true # 啟動ConfigFilter #配置初始化大小/最小/最大[僅用于測試,生產(chǎn)環(huán)境需要修改] initial-size: 5 min-idle: 5 max-active: 20 #獲取連接等待超時時間 max-wait: 60000 #間隔多久進行一次檢測,檢測需要關閉的空閑連接 time-between-eviction-runs-millis: 10000 #一個連接在池中最小生存的時間 min-evictable-idle-time-millis: 300000 #指定獲取連接時連接校驗的sql查詢語句 validation-query: SELECT 'x' #驗證連接的有效性 test-while-idle: true #獲取連接時候驗證,會影響性能(不建議true) test-on-borrow: false #打開PSCache,并指定每個連接上PSCache的大小。oracle設為true,mysql設為false。分庫分表較多推薦設置為false pool-prepared-statements: false max-pool-prepared-statement-per-connection-size: 20 publicKey: MFwwDQYJKoZIhafwqfDSAwAwSAJBAIG3LgXwadfgferwbWdkGNDzgrjfSWfrBjJ2X+m9lajH7yGPeE/vLs4hdtr1RCITBKJeevZpwZ0DBLctVS6Dc0CAwEAAQ==
到此這篇關于springboot 整合druid數(shù)據(jù)庫密碼加密功能的實現(xiàn)代碼的文章就介紹到這了,更多相關springboot 整合druid密碼加密內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
- SpringBoot+Druid開啟監(jiān)控頁面的實現(xiàn)示例
- SpringBoot整合Druid實現(xiàn)SQL監(jiān)控和數(shù)據(jù)庫密碼加密
- SpringBoot整合mybatis使用Druid做連接池的方式
- SpringBoot整合Mybatis-Plus+Druid實現(xiàn)多數(shù)據(jù)源配置功能
- springboot 整合druid及配置依賴
- 解決springboot整合druid遇到的坑
- SpringBoot整合Druid數(shù)據(jù)源過程詳解
- 詳解Spring Boot整合Mybatis實現(xiàn) Druid多數(shù)據(jù)源配置
- Spring Boot 整合 Druid 并開啟監(jiān)控的操作方法
相關文章
在Java中String和Date、Timestamp之間的轉換
這篇文章主要介紹了在Java中String和Date、Timestamp之間的轉換 的相關資料,需要的朋友可以參考下2015-12-12微信開發(fā)準備第二步 springmvc mybatis項目結構搭建
這篇文章主要為大家詳細介紹了微信開發(fā)準備第二步,springmvc和mybatis項目結構的搭建,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04