日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

若依框架数据库密码加密

發(fā)布時間:2023/12/10 数据库 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 若依框架数据库密码加密 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1. 用 Druid 提供的方法加密密碼,控制臺會輸出三對值,分別是:privateKey、publicKey、password

public static void main(String[] args) {String password = "password";try {ConfigTools.main(new String[]{password});} catch (Exception e) {e.printStackTrace();} }

2. 將 application-druid.yml 中的 druid.master.password 替換成加密后的 password

3. application-druid.yml 的 druid 直接子級添加配置項,config.decrypt.key 填寫生成的 publicKey

filters:config:# 數(shù)據(jù)庫密碼是否加密開關(guān),false 表示密碼使用明文enabled: true connect-properties:config.decrypt: trueconfig.decrypt.key:

4. 修改 com.ruoyi.framework.config.properties.DruidProperties,添加以下代碼

@Value("${spring.datasource.druid.filters.config.enabled}") private boolean configFilterEnabled;@Value("${spring.datasource.druid.connect-properties.config.decrypt}") private String decryptEnabled;@Value("${spring.datasource.druid.connect-properties.config.decrypt.key}") private String decryptKey;// dataSource 方法中添加 if (configFilterEnabled) {try {/* 啟用數(shù)據(jù)庫密碼解密 */datasource.setFilters("config");Properties properties = new Properties();properties.put("config.decrypt", decryptEnabled);properties.put("config.decrypt.key", decryptKey);datasource.setConnectProperties(properties);} catch (Exception exception) {exception.printStackTrace();} }

以下是 DruidProperties 的完整代碼

package com.ruoyi.framework.config.properties;import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import com.alibaba.druid.pool.DruidDataSource;import java.util.Properties;/*** druid 配置屬性* * @author ruoyi*/ @Configuration public class DruidProperties {@Value("${spring.datasource.druid.initialSize}")private int initialSize;@Value("${spring.datasource.druid.minIdle}")private int minIdle;@Value("${spring.datasource.druid.maxActive}")private int maxActive;@Value("${spring.datasource.druid.maxWait}")private int maxWait;@Value("${spring.datasource.druid.timeBetweenEvictionRunsMillis}")private int timeBetweenEvictionRunsMillis;@Value("${spring.datasource.druid.minEvictableIdleTimeMillis}")private int minEvictableIdleTimeMillis;@Value("${spring.datasource.druid.maxEvictableIdleTimeMillis}")private int maxEvictableIdleTimeMillis;@Value("${spring.datasource.druid.validationQuery}")private String validationQuery;@Value("${spring.datasource.druid.testWhileIdle}")private boolean testWhileIdle;@Value("${spring.datasource.druid.testOnBorrow}")private boolean testOnBorrow;@Value("${spring.datasource.druid.testOnReturn}")private boolean testOnReturn;@Value("${spring.datasource.druid.filters.config.enabled}")private boolean configFilterEnabled;@Value("${spring.datasource.druid.connect-properties.config.decrypt}")private String decryptEnabled;@Value("${spring.datasource.druid.connect-properties.config.decrypt.key}")private String decryptKey;public DruidDataSource dataSource(DruidDataSource datasource){/** 配置初始化大小、最小、最大 */datasource.setInitialSize(initialSize);datasource.setMaxActive(maxActive);datasource.setMinIdle(minIdle);/** 配置獲取連接等待超時的時間 */datasource.setMaxWait(maxWait);/** 配置間隔多久才進行一次檢測,檢測需要關(guān)閉的空閑連接,單位是毫秒 */datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);/** 配置一個連接在池中最小、最大生存的時間,單位是毫秒 */datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);datasource.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis);/*** 用來檢測連接是否有效的sql,要求是一個查詢語句,常用select 'x'。如果validationQuery為null,testOnBorrow、testOnReturn、testWhileIdle都不會起作用。*/datasource.setValidationQuery(validationQuery);/** 建議配置為true,不影響性能,并且保證安全性。申請連接的時候檢測,如果空閑時間大于timeBetweenEvictionRunsMillis,執(zhí)行validationQuery檢測連接是否有效。 */datasource.setTestWhileIdle(testWhileIdle);/** 申請連接時執(zhí)行validationQuery檢測連接是否有效,做了這個配置會降低性能。 */datasource.setTestOnBorrow(testOnBorrow);/** 歸還連接時執(zhí)行validationQuery檢測連接是否有效,做了這個配置會降低性能。 */datasource.setTestOnReturn(testOnReturn);if (configFilterEnabled) {try {/* 啟用數(shù)據(jù)庫密碼解密 */datasource.setFilters("config");Properties properties = new Properties();properties.put("config.decrypt", decryptEnabled);properties.put("config.decrypt.key", decryptKey);datasource.setConnectProperties(properties);} catch (Exception exception) {exception.printStackTrace();}}return datasource;} }

?

總結(jié)

以上是生活随笔為你收集整理的若依框架数据库密码加密的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。