springboot整合jasypt的詳細(xì)過程
jasypt
保證項(xiàng)目中的賬號(hào)密碼不以明文的形式展示
springboot集成jasypt
1.引入maven依賴
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.4</version>
</dependency>2.啟動(dòng)類添加注解
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.加解密測(cè)試類
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);
}
}到此這篇關(guān)于springboot整合jasypt的文章就介紹到這了,更多相關(guān)springboot整合jasypt內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解決JdbcTemplate查詢時(shí)報(bào)錯(cuò)Incorrect column count: ex
文章描述了在使用JdbcTemplate執(zhí)行查詢時(shí)遇到的`IncorrectResultSetColumnCountException`錯(cuò)誤,原因是`queryForList`方法返回的是`List<Map<String, Object>>`類型,不能直接轉(zhuǎn)換成對(duì)象,解決方法是將代碼修改為適當(dāng)?shù)牟樵兎绞?以避免錯(cuò)誤2026-01-01
windows系統(tǒng)配置Java開發(fā)環(huán)境變量
這篇文章主要介紹了windows系統(tǒng)配置Java開發(fā)環(huán)境變量,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2021-12-12
SpringBoot3 整合Docker-Compose的實(shí)現(xiàn)步驟
本文主要介紹了SpringBoot3 整合Docker-Compose的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-08-08
Quarkus的Spring擴(kuò)展快速改造Spring項(xiàng)目
這篇文章主要為大家介紹了Quarkus的Spring項(xiàng)目擴(kuò)展,帶大家快速改造Spring項(xiàng)目示例演繹,有需要的朋友可以借鑒參考下,希望能夠有所幫助2022-02-02
SpringBoot整合RabbitMQ實(shí)現(xiàn)消息確認(rèn)機(jī)制
這篇文章主要介紹了SpringBoot整合RabbitMQ實(shí)現(xiàn)消息確認(rèn)機(jī)制,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-08-08
Java用數(shù)組實(shí)現(xiàn)循環(huán)隊(duì)列的示例
下面小編就為大家?guī)硪黄狫ava用數(shù)組實(shí)現(xiàn)循環(huán)隊(duì)列的示例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-09-09

