国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:74日期:2023-04-16 18:12:35

jasypt是一個通用的加解密庫,我們可以使用它在配置文件中對數(shù)據(jù)庫密碼進(jìn)行加密,以確保其安全性。

1、注入依賴

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

2、配置文件

#以數(shù)據(jù)庫密碼加密為例## 數(shù)據(jù)源配置spring.datasource.url=jdbc:mysql://lochost:3306/jasypt?characterEncoding=utf8spring.datasource.username=root#Fddt+VfcW5+j5lAbuOXxPB3mGb0iBLLe 是采用jasypt進(jìn)行加密以后生成的密文spring.datasource.password=ENC(Fddt+VfcW5+j5lAbuOXxPB3mGb0iBLLe)spring.datasource.driver-class-name=com.mysql.jdbc.Driver#jasypt加密的密匙jasypt.encryptor.password=abcderf(這個是自己設(shè)置的)

那么如何得到這個密文呢?

1、win+r cmd打開命令窗口 在你的maven庫中找到 jasypt-1.9.2.jar 包執(zhí)行下面的命令

java -cp D:Mavenrepositoryorgjasyptjasypt1.9.2jasypt-1.9.2.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input='密鑰(abcderf)' password=root(加密的密碼) algorithm=PBEWithMD5AndDES

然后復(fù)制密文即可

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

2、代碼生成(這種方法沒有使用過 參考鏈接:https://www.jb51.net/article/197600.htm)

import org.jasypt.util.text.BasicTextEncryptor;public class Test {public static void main(String[] args) { BasicTextEncryptor textEncryptor = new BasicTextEncryptor(); //加密所需的salt(鹽) textEncryptor.setPassword('PBEWithMD5AndDES'); //要加密的數(shù)據(jù)(數(shù)據(jù)庫的用戶名或密碼) String username = textEncryptor.encrypt('root'); String password = textEncryptor.encrypt('root'); System.out.println('username:'+username); System.out.println('password:'+password); }}

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

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 庐江县| 宝兴县| 合肥市| 铜梁县| 蒲城县| 丰原市| 五峰| 鄂托克旗| 东阳市| 巴塘县| 南昌县| 固阳县| 博湖县| 富平县| 兴山县| 汉沽区| 江口县| 台南县| 潮安县| 枣强县| 修武县| 眉山市| 都安| 铁岭县| 洪洞县| 永定县| 鄂伦春自治旗| 游戏| 东乡族自治县| 明溪县| 太湖县| 东乡县| 四子王旗| 清涧县| 宁城县| 久治县| 洪湖市| 新绛县| 台中市| 大埔县| 铜陵市|