欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

使用@SpringBootApplication注解啟動的項目,只需增加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");     // 加密的算法,這個算法是默認的
    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項目application.yml文件數(shù)據(jù)庫配置密碼加密的方法的文章就介紹到這了,更多相關(guān)SpringBoot application.yml數(shù)據(jù)庫加密內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論