在SpringBoot中通過jasypt進行加密解密的方法
1.用途
在SpringBoot中,通過jasypt可以進行加密解密. 這個是雙向的, 且可以配置密鑰.
2.使用:
2.1通過UT創(chuàng)建工具類,并認識jasypt
import org.jasypt.util.text.BasicTextEncryptor; import org.junit.Test; public class UtilTests { @Test public void jasyptTest() { BasicTextEncryptor encryptor = new BasicTextEncryptor(); // application.properties, jasypt.encryptor.password encryptor.setPassword("abc"); // encrypt root System.out.println(encryptor.encrypt("root")); System.out.println(encryptor.encrypt("root")); System.out.println(encryptor.encrypt("root")); // decrypt, the result is root System.out.println(encryptor.decrypt("UP/yojB7ie3apnh3mLTU7w==")); System.out.println(encryptor.decrypt("ik9FE3GiYLiHwchiyHg9QQ==")); System.out.println(encryptor.decrypt("9Obo/jq9EqmTE0QZaJFYrw==")); } }
可以看出, 每次生成的密碼是不一樣的, 但是通過密鑰,可以解密成一樣的明文.
2.2在SpringBoot中配置jasypt
2.2.1配置密鑰
jasypt.encryptor.password:abc
2.2.2使用
spring.datasource.url: jdbc:mysql://127.0.0.1:3306/tmp?useSSL=false&useUnicode=true&characterEncoding=utf-8
spring.datasource.username: ENC(ik9FE3GiYLiHwchiyHg9QQ==)
spring.datasource.password: ENC(ik9FE3GiYLiHwchiyHg9QQ==)
spring.datasource.driver-class-name: com.mysql.jdbc.Driver
2.2.3啟動時配置密鑰
java -jar -Djasypt.encryptor.password=abc xxx.jar
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
相關(guān)文章
SpringBoot集成內(nèi)存數(shù)據(jù)庫H2的實踐
h2是內(nèi)存數(shù)據(jù)庫,查詢高效,可以在開發(fā)初期使用它。本文主要介紹了SpringBoot集成內(nèi)存數(shù)據(jù)庫H2的實踐,具有一定的參考價值,感興趣的可以了解一下2021-09-09解決Feign配置RequestContextHolder.getRequestAttributes()為null的問題
這篇文章主要介紹了解決Feign配置RequestContextHolder.getRequestAttributes()為null的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-01-01spring5 SAXParseException:cvc-elt.1: 找不到元素“beans 的聲明詳解
這篇文章主要給大家介紹了關(guān)于spring5 SAXParseException:cvc-elt.1: 找不到元素“beans 聲明的相關(guān)資料,需要的朋友可以參考下2020-08-08