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依賴
我們對信息加解密是使用這個(gè)jar包的:
編寫加解密測試類:
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)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. xml創(chuàng)建節(jié)點(diǎn)(根節(jié)點(diǎn)、子節(jié)點(diǎn))2. ASP.NET MVC使用jQuery ui的progressbar實(shí)現(xiàn)進(jìn)度條3. 淺談Python中文件夾和python package包的區(qū)別4. 關(guān)于Python Socket編程的要點(diǎn)詳解5. java 實(shí)現(xiàn)Comparable接口排序,升序、降序、倒敘6. Java實(shí)現(xiàn)RedisUtils操作五大集合(增刪改查)7. Python selenium模擬網(wǎng)頁點(diǎn)擊爬蟲交管12123違章數(shù)據(jù)8. Python基礎(chǔ)之numpy庫的使用9. PHP json_encode中文亂碼解決方法10. Python中常見的數(shù)制轉(zhuǎn)換有哪些
