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

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

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

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

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

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進行加密以后生成的密文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 包執(zhí)行下面的命令

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

然后復制密文即可

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); }}

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

標簽: Spring
相關文章:
主站蜘蛛池模板: 永宁县| 福贡县| 九龙城区| 垦利县| 三台县| 东城区| 司法| 栖霞市| 桐柏县| 星子县| 湾仔区| 临西县| 凤阳县| 沈阳市| 平阳县| 和龙市| 通州区| 盐山县| 都兰县| 静乐县| 和龙市| 沙洋县| 九台市| 海原县| 三江| 鸡西市| 峨眉山市| 孝感市| 宜黄县| 宜都市| 武穴市| 永新县| 蒲城县| 清原| 中卫市| 锡林郭勒盟| 武强县| 卢龙县| 蒙阴县| 高阳县| 开原市|