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 #間隔多久進行一次檢測,檢測需要關(guān)閉的空閑連接 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設(shè)為true,mysql設(shè)為false。分庫分表較多推薦設(shè)置為false pool-prepared-statements: false max-pool-prepared-statement-per-connection-size: 20publicKey: MFwwDQYJKoZIhafwqfDSAwAwSAJBAIG3LgXwadfgferwbWdkGNDzgrjfSWfrBjJ2X+m9lajH7yGPeE/vLs4hdtr1RCITBKJeevZpwZ0DBLctVS6Dc0CAwEAAQ==
到此這篇關(guān)于springboot 整合druid數(shù)據(jù)庫密碼加密功能的實現(xiàn)代碼的文章就介紹到這了,更多相關(guān)springboot 整合druid密碼加密內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. .NET中l(wèi)ambda表達式合并問題及解決方法2. JSP數(shù)據(jù)交互實現(xiàn)過程解析3. 淺談python出錯時traceback的解讀4. 利用promise及參數(shù)解構(gòu)封裝ajax請求的方法5. Python importlib動態(tài)導(dǎo)入模塊實現(xiàn)代碼6. python matplotlib:plt.scatter() 大小和顏色參數(shù)詳解7. windows服務(wù)器使用IIS時thinkphp搜索中文無效問題8. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向9. 在Android中使用WebSocket實現(xiàn)消息通信的方法詳解10. Nginx+php配置文件及原理解析
