欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot 整合druid數(shù)據(jù)庫密碼加密功能的實現(xiàn)代碼

 更新時間:2021年01月07日 09:03:22   作者:謙竹墨客  
這篇文章主要介紹了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ù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論