最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot項(xiàng)目application.yml文件數(shù)據(jù)庫配置密碼加密的方法

 更新時間:2020年03月22日 15:38:31   作者:辰小白  
這篇文章主要介紹了SpringBoot項(xiàng)目application.yml文件數(shù)據(jù)庫配置密碼加密的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

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

使用@SpringBootApplication注解啟動的項(xiàng)目,只需增加maven依賴

我們對信息加解密是使用這個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");     // 加密的算法,這個算法是默認(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({加密串})即可。

啟動時需要配置 秘鑰

將秘鑰加入啟動參數(shù)

到此這篇關(guān)于SpringBoot項(xiàng)目application.yml文件數(shù)據(jù)庫配置密碼加密的方法的文章就介紹到這了,更多相關(guān)SpringBoot application.yml數(shù)據(jù)庫加密內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

额敏县| 社旗县| 新竹县| 泉州市| 南澳县| 册亨县| 武川县| 阜新市| 莱州市| 襄樊市| 惠安县| 安宁市| 金沙县| 灵台县| 门头沟区| 本溪市| 马龙县| 叶城县| 九江市| 乐清市| 平顶山市| 清新县| 漳州市| 塘沽区| 工布江达县| 辉南县| 连山| 绥阳县| 湖南省| 蓝山县| 罗山县| 浦东新区| 祁连县| 平湖市| 常熟市| 晴隆县| 湖北省| 墨竹工卡县| 木兰县| 星子县| 苏尼特左旗|