国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

SpringBoot項目application.yml文件數據庫配置密碼加密的方法

瀏覽:40日期:2023-05-27 11:38:16

在Spring boot開發中,需要在application.yml文件里配置數據庫的連接信息,或者在啟動時傳入數據庫密碼,如果不加密,傳明文,數據庫就直接暴露了,相當于'裸奔'了,因此需要進行加密處理才行。

使用@SpringBootApplication注解啟動的項目,只需增加maven依賴

SpringBoot項目application.yml文件數據庫配置密碼加密的方法

我們對信息加解密是使用這個jar包的:

SpringBoot項目application.yml文件數據庫配置密碼加密的方法

編寫加解密測試類:

package cn.linjk.ehome; import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;import org.jasypt.encryption.pbe.config.EnvironmentPBEConfig;import org.junit.Test; public class JasyptTest { @Test public void testEncrypt() throws Exception { StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor(); EnvironmentPBEConfig config = new EnvironmentPBEConfig(); config.setAlgorithm('PBEWithMD5AndDES'); // 加密的算法,這個算法是默認的 config.setPassword('test'); // 加密的密鑰 standardPBEStringEncryptor.setConfig(config); String plainText = '88888888'; String encryptedText = standardPBEStringEncryptor.encrypt(plainText); System.out.println(encryptedText); } @Test public void testDe() throws Exception { StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor(); EnvironmentPBEConfig config = new EnvironmentPBEConfig(); config.setAlgorithm('PBEWithMD5AndDES'); config.setPassword('test'); standardPBEStringEncryptor.setConfig(config); String encryptedText = 'ip10XNIEfAMTGQLdqt87XnLRsshu0rf0'; String plainText = standardPBEStringEncryptor.decrypt(encryptedText); System.out.println(plainText); }}

加密串拿到了,現在來修改application.yml的配置:

我們把加密串放在ENC({加密串})即可。

SpringBoot項目application.yml文件數據庫配置密碼加密的方法

啟動時需要配置 秘鑰

將秘鑰加入啟動參數

SpringBoot項目application.yml文件數據庫配置密碼加密的方法

SpringBoot項目application.yml文件數據庫配置密碼加密的方法

到此這篇關于SpringBoot項目application.yml文件數據庫配置密碼加密的方法的文章就介紹到這了,更多相關SpringBoot application.yml數據庫加密內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 乳山市| 枣庄市| 北安市| 阿城市| 海门市| 上蔡县| 乌审旗| 方山县| 蒙城县| 长岛县| 班玛县| 通江县| 稻城县| 林西县| 宜都市| 壶关县| 延边| 保靖县| 宁波市| 乌鲁木齐县| 上蔡县| 巴东县| 民权县| 枣强县| 德令哈市| 库车县| 陕西省| 富川| 海晏县| 盐津县| 电白县| 太和县| 盖州市| 九江县| 盘锦市| 金乡县| 如东县| 阳东县| 涟源市| 亚东县| 安溪县|