SpringBoot項(xiàng)目application.yml文件數(shù)據(jù)庫配置密碼加密的方法
在Spring boot開發(fā)中,需要在application.yml文件里配置數(shù)據(jù)庫的連接信息,或者在啟動(dòng)時(shí)傳入數(shù)據(jù)庫密碼,如果不加密,傳明文,數(shù)據(jù)庫就直接暴露了,相當(dāng)于'裸奔'了,因此需要進(jìn)行加密處理才行。
使用@SpringBootApplication注解啟動(dòng)的項(xiàng)目,只需增加maven依賴
我們對(duì)信息加解密是使用這個(gè)jar包的:
編寫加解密測(cè)試類:
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'); // 加密的算法,這個(gè)算法是默認(rèn)的 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); }}
加密串拿到了,現(xiàn)在來修改application.yml的配置:
我們把加密串放在ENC({加密串})即可。
啟動(dòng)時(shí)需要配置 秘鑰
將秘鑰加入啟動(dòng)參數(shù)
到此這篇關(guān)于SpringBoot項(xiàng)目application.yml文件數(shù)據(jù)庫配置密碼加密的方法的文章就介紹到這了,更多相關(guān)SpringBoot application.yml數(shù)據(jù)庫加密內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Java8內(nèi)存模型PermGen Metaspace實(shí)例解析2. HTML DOM setInterval和clearInterval方法案例詳解3. 利用CSS3新特性創(chuàng)建透明邊框三角4. HTML <!DOCTYPE> 標(biāo)簽5. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)6. HTML5 Canvas繪制圖形從入門到精通7. 小技巧處理div內(nèi)容溢出8. 存儲(chǔ)于xml中需要的HTML轉(zhuǎn)義代碼9. XML入門精解之結(jié)構(gòu)與語法10. XML入門的常見問題(一)
