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

SpringBoot使用jasypt加解密密碼的實(shí)現(xiàn)方法(二)

 更新時(shí)間:2020年10月17日 12:27:10   作者:自行車上的程序員  
這篇文章主要介紹了SpringBoot使用jasypt加解密密碼的實(shí)現(xiàn)方法(二),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

在我們的服務(wù)中不可避免的需要使用到一些秘鑰(數(shù)據(jù)庫(kù)、redis等)

開(kāi)發(fā)和測(cè)試環(huán)境還好,但生產(chǎn)如果采用明文配置講會(huì)有安全問(wèn)題,jasypt是一個(gè)通用的加解密庫(kù),我們可以使用它。

<dependency>
  <groupId>com.github.ulisesbocchio</groupId>
  <artifactId>jasypt-spring-boot-starter</artifactId>
  <version>2.1.1</version>
</dependency>

配置文件:

# 加密的密鑰
# 測(cè)試環(huán)境可以采用在配置文件中配置
# 生產(chǎn)環(huán)境建議采用啟動(dòng)參數(shù)的形式傳入
# 其他配置參數(shù)參考:com.ulisesbocchio.jasyptspringboot.properties.JasyptEncryptorConfigurationProperties
jasypt.encryptor.password=you salt

# 解密得到原始密碼
spring.datasource.password= ENC(密文)

那密文怎么來(lái)的呢?

@Autowired
StringEncryptor stringEncryptor;

@Test
public void encrypt() {
  System.out.println("PWD: " + stringEncryptor.encrypt("yourpassword"));
}
public static void main(String[] args) {
    BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
    //加密所需的salt(鹽)
    textEncryptor.setPassword("G0CvDz7oJn6");
    //要加密的數(shù)據(jù)(數(shù)據(jù)庫(kù)的用戶名或密碼)
    String username = textEncryptor.encrypt("root");
    String password = textEncryptor.encrypt("root123");
    System.out.println("username:"+username);
    System.out.println("password:"+password);
  }

jasypt默認(rèn)使用StringEncryptor來(lái)進(jìn)行加解密,我們也可以自定義自己的加解密類來(lái)替換它,具體用戶用時(shí)請(qǐng)百度/google。

到此這篇關(guān)于SpringBoot使用jasypt加解密密碼的實(shí)現(xiàn)方法(二)的文章就介紹到這了,更多相關(guān)SpringBoot加解密密碼內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論