久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

SpringBoot使用jasypt加解密密碼的實現方法

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

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

1、注入依賴

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

2、配置文件

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

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

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

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

然后復制密文即可

SpringBoot使用jasypt加解密密碼的實現方法

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'); //要加密的數據(數據庫的用戶名或密碼) String username = textEncryptor.encrypt('root'); String password = textEncryptor.encrypt('root'); System.out.println('username:'+username); System.out.println('password:'+password); }}

到此這篇關于SpringBoot使用jasypt加解密密碼的實現方法的文章就介紹到這了,更多相關SpringBoot加解密密碼內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 布拖县| 巴南区| 宣恩县| 萨迦县| 五寨县| 南城县| 上林县| 赤城县| 湘西| 文化| 昭苏县| 乐山市| 灵璧县| 萍乡市| 长泰县| 临西县| 崇信县| 团风县| 喀喇沁旗| 留坝县| 淳安县| 河间市| 延津县| 阿瓦提县| 上栗县| 泸溪县| 白朗县| 涿鹿县| 鸡西市| 新余市| 醴陵市| 曲水县| 威宁| 新乐市| 曲阳县| 白河县| 韶关市| 绍兴市| 甘孜| 竹溪县| 瓦房店市|