springboot整合jasypt的詳細過程
更新時間:2024年02月19日 14:44:31 作者:果殼~
這篇文章主要介紹了springboot整合jasypt的詳細過程,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧
jasypt
保證項目中的賬號密碼不以明文的形式展示
springboot集成jasypt
1.引入maven依賴
<dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>3.0.4</version> </dependency>
2.啟動類添加注解
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @EnableEncryptableProperties public class IpSourceApplication { public static void main(String[] args) { SpringApplication.run(IpSourceApplication.class, args); } }
3.yaml配置
jasypt: encryptor: password: 02700083-9fd9-4b82-a4b4-9177e0560e92 algorithm: PBEWithMD5AndDES iv-generator-classname: org.jasypt.iv.NoIvGenerator my: username: ENC(atRC+VNwB17CQVilGftfQg==) password: ENC(Or0FKbtskiXsJlFtI23FxA==)
4.加解密測試類
import org.jasypt.util.text.BasicTextEncryptor; public class Test01 { public static void main(String[] args) { //該類的選擇根據(jù)algorithm:PBEWithMD5AndDE選擇的算法選擇 BasicTextEncryptor encryptor = new BasicTextEncryptor(); encryptor.setPassword("02700083-9fd9-4b82-a4b4-9177e0560e92"); String encrypt = encryptor.encrypt("root"); System.out.println(encrypt); String decrypt = encryptor.decrypt(encrypt); System.out.println(decrypt); encrypt = encryptor.encrypt("mysql"); System.out.println(encrypt); decrypt = encryptor.decrypt(encrypt); System.out.println(decrypt); } }
讀取配置效果
@RestController public class IpController implements InitializingBean { @Value("${my.username}") private String username; @Value("${my.password}") private String password; @Override public void afterPropertiesSet() throws Exception { System.out.println("username:"+username+",password:"+password); } }
到此這篇關于springboot整合jasypt的文章就介紹到這了,更多相關springboot整合jasypt內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
SpringBoot如何優(yōu)雅地使用Swagger2
這篇文章主要介紹了SpringBoot如何優(yōu)雅地使用Swagger2,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-07-07Mybatis-Plus使用updateById()、update()將字段更新為null
本文主要介紹了Mybatis-Plus使用updateById()、update()將字段更新為null,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-08-08SpringBoot封裝自己的Starter的實現(xiàn)方法
這篇文章主要介紹了SpringBoot封裝自己的Starter的實現(xiàn)方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-04-04SpringBoot+MyBatisPlus+Vue 前后端分離項目快速搭建過程(前端篇)
這篇文章主要介紹了SpringBoot+MyBatisPlus+Vue 前后端分離項目快速搭建過程(前端篇),本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-05-05