国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

SpringBoot+jasypt-spring-boot-starter實(shí)現(xiàn)配置文件明文加密

這篇具有很好參考價(jià)值的文章主要介紹了SpringBoot+jasypt-spring-boot-starter實(shí)現(xiàn)配置文件明文加密。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

1.使用環(huán)境

springboot:2.1.4.RELEASE
JDK:8
jasypt-spring-boot-starter:3.0.2
Jasypt默認(rèn)算法為PBEWithMD5AndDES,該算法需要一個(gè)加密密鑰,可以在應(yīng)用啟動(dòng)時(shí)指定(環(huán)境變量)。也可以直接寫(xiě)入配置文件

2.引入依賴

!-- 配置文件加密 -->
<dependency>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-spring-boot-starter</artifactId>
    <version>3.0.2</version>
</dependency>


<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.0.1</version>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.33</version>
</dependency>

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

3.加密方式

3.1 application.properties配置文件版
server.port=8080

### mybatis
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=com.xx.xx  

### xxl-job, datasource
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxx?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=ENC(jGfd15IFYKMjMW5bUYp06BQ8OCdHTXi3zbD4j9tw6U3PPvvA5GS8zn10kgVmgxXY)
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

#加密鹽值,獲取加密后的值后刪除,在vmOptions配置(如下圖)
jasypt.encryptor.password=123adf
@SpringBootTest
@RunWith(SpringRunner.class)
public class D2ApplicationTests {

    @Resource
    private StringEncryptor jasyptStringEncryptor;
    @Test
    public void contextLoads() {
       String pwd =  jasyptStringEncryptor.encrypt("root");
        System.out.println("pwd:" + pwd);
    }

}

加密后,可刪除jasypt.encryptor.password配置;發(fā)版時(shí)可在命令行中配置
SpringBoot+jasypt-spring-boot-starter實(shí)現(xiàn)配置文件明文加密,SpringBoot,JAVA,開(kāi)發(fā)工具,spring boot,后端,java

3.2 函數(shù)版
// 創(chuàng)建加密對(duì)象,默認(rèn) PBEWithMD5AndDES
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
// 加密所需的密鑰
textEncryptor.setPassword("password");
// 加密后的數(shù)據(jù)(數(shù)據(jù)庫(kù)的用戶名或密碼)
String encData = textEncryptor.encrypt("Password@1");
// 解密后的數(shù)據(jù)(原數(shù)據(jù))
String decData = textEncryptor.decrypt(encData);
System.out.println("encData: " + encData);
System.out.println("decData: " + decData);

4.所遇問(wèn)題

org.jasypt.exceptions.EncryptionOperationNotPossibleException:
Encryption raised an exception.
A possible cause is you are using strong encryption algorithms and you have not 
installed the Java Cryptography Extension (JCE) Unlimited Strength 
Jurisdiction Policy Files in this Java Virtual Machine

解決方案:java密碼擴(kuò)展無(wú)限制權(quán)限策略文件安裝–jce_policy安裝
文件下載地址:
下面為下載鏈接

JDK 1.7–jce安裝地址:JDK1.7 -jce地址

JDK 1.8–jce安裝地址:JDK 1.8–jce安裝地址

相關(guān)文件來(lái)自于博客:https://www.cnblogs.com/zgngg/p/13859299.html) 感謝博主:瘋狂的⑨醬 的無(wú)私奉獻(xiàn)

jar配置路徑:
JDK:將兩個(gè)jar文件放到%JDK_HOME%\jre\lib\security下
JRE:將兩個(gè)jar文件放到%JRE_HOME%\lib\security下文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-610088.html

到了這里,關(guān)于SpringBoot+jasypt-spring-boot-starter實(shí)現(xiàn)配置文件明文加密的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Springboot實(shí)戰(zhàn)之spring-boot-starter-data-elasticsearch搭建ES搜索接口

    Springboot實(shí)戰(zhàn)之spring-boot-starter-data-elasticsearch搭建ES搜索接口

    本教程是本人親自實(shí)戰(zhàn)的,然后運(yùn)行起來(lái)的全部步驟。 環(huán)境 Elasticsearch 7.15.2 Kibana 7.15.2 springboot 2.6.4 以及對(duì)應(yīng)的spring-boot-starter-web和spring-boot-starter-data-elasticsearch fastjson 1.2.97 安裝好Elasticsearch7.15.2以及對(duì)應(yīng)的Kibana。 去Springboot Start 新建項(xiàng)目 使用 devtools 創(chuàng)建 number_of_shards 數(shù)據(jù)分

    2023年04月08日
    瀏覽(22)
  • 【Jasypt】Spring Boot 配置文件加解密 Jasypt 配置文件加密

    【Jasypt】Spring Boot 配置文件加解密 Jasypt 配置文件加密

    Jasypt是一個(gè)Java簡(jiǎn)易加密庫(kù),用于加密配置文件中的敏感信息,如數(shù)據(jù)庫(kù)密碼。jasypt庫(kù)與springboot集成,在實(shí)際開(kāi)發(fā)中非常方便。 1、Jasypt Spring Boot 為 spring boot 應(yīng)用程序中的屬性源提供加密支持,出于安全考慮,Spring boot 配置文件中的敏感信息通常需要對(duì)它進(jìn)行加密/脫敏處理,

    2024年02月03日
    瀏覽(20)
  • springboot web創(chuàng)建失敗,解決Could not find artifact org.springframework.boot:spring-boot-starter-parent:pom

    springboot web創(chuàng)建失敗,解決Could not find artifact org.springframework.boot:spring-boot-starter-parent:pom

    jdk8不支持3.0以上的springboot版本,如果你在創(chuàng)建項(xiàng)目的時(shí)候用的是jdk8,那么我建議你在創(chuàng)建好項(xiàng)目之后自行再pom文件里降級(jí),我剛開(kāi)始接觸springboot時(shí),用的是jdk11,導(dǎo)入的springboot版本是2.7.1,然后弄了差不多半天都找不到原因,然后我就擴(kuò)大了阿里云的搜索地址,自行在pom文

    2024年02月04日
    瀏覽(32)
  • springboot 發(fā)送郵件,以及郵件工具類 并且解決spring-boot-starter-mail 發(fā)送郵件附件亂碼或者文件錯(cuò)亂

    1、設(shè)置系統(tǒng)值 System.setProperty(“mail.mime.splitlongparameters”, “false”); 2、 在創(chuàng)建對(duì)象的時(shí)候定義編碼格式(utf-8): MimeMessageHelper helper = new MimeMessageHelper(mes, true, “utf-8”); 3、 其次,在添加附件的時(shí)候,附件名是需要定義編碼的 helper.addAttachment(MimeUtility.encodeWord(附件名,“utf-8”

    2024年02月15日
    瀏覽(34)
  • Java使用Milo實(shí)現(xiàn)OPC UA客戶端,封裝spring boot starter

    Java使用Milo實(shí)現(xiàn)OPC UA客戶端,封裝spring boot starter

    最新版本更新日志查看:https://github.com/kangaroo1122/milo-spring-boot-starter/blob/main/UPDATE.md、https://gitee.com/vampire001/milo-spring-boot-starter/blob/master/UPDATE.md,此處不再更新 由eclipse開(kāi)源,地址:https://github.com/eclipse/milo,可以基于此開(kāi)發(fā)OPC UA客戶端或者服務(wù)端。 本文介紹基于milo 封裝的sp

    2024年02月09日
    瀏覽(27)
  • 在Spring Boot微服務(wù)使用jasypt-spring-boot加密和解密yml配置文件

    記錄 :424 場(chǎng)景 :在Spring Boot微服務(wù),使用jasypt-spring-boot加密和解密yml配置文件中的配置信息。 版本 :JDK 1.8,Spring?Boot 2.6.3,jasypt-1.9.3,jasypt-spring-boot-2.1.2, jasypt-spring-boot-3.0.5。 開(kāi)源地址 :https://github.com/ulisesbocchio/jasypt-spring-boot 1.在Spring Boot微服務(wù)使用jasypt-spring-boot-3.0.5版本

    2024年02月09日
    瀏覽(21)
  • Spring Boot使用jasypt處理數(shù)據(jù)庫(kù)賬號(hào)密碼等數(shù)據(jù)加密問(wèn)題

    在我們業(yè)務(wù)場(chǎng)景中,項(xiàng)目中的application.yml 配置文件比如數(shù)據(jù)庫(kù)賬號(hào)密碼,的各種鏈接的username,password的值都是明文的,存在一定的安全隱患,可以使用jasypt?加密框架的方式進(jìn)行明文加密,進(jìn)而使得我們項(xiàng)目更加安全 注意這里排除了mybatis-plus的包可能是項(xiàng)目中有沖突依賴,

    2024年02月06日
    瀏覽(29)
  • jasypt-spring-boot敏感信息加密解密利器使用指南

    jasypt-spring-boot敏感信息加密解密利器使用指南

    Springboot 整合Jasypt,實(shí)現(xiàn)配置信息的安全,如數(shù)據(jù)庫(kù)連接.賬號(hào)和密碼.接口憑證信息等。 Jasypt可以為Springboot加密的信息很多,主要有: System Property 系統(tǒng)變量 Envirnment Property 環(huán)境變量 Command Line argument 命令行參數(shù) Application.properties 應(yīng)用配置文件 Yaml properties 應(yīng)用配置文件 other

    2024年02月03日
    瀏覽(33)
  • Spring Boot - spring-boot-starter

    spring-boot-starter 當(dāng)學(xué)習(xí)Spring Boot時(shí),可以通過(guò)一個(gè)完整的案例來(lái)理解和實(shí)踐其基本概念和功能。以下是一個(gè)簡(jiǎn)單的Spring Boot Starter完整案例,展示了如何創(chuàng)建一個(gè)基本的Web應(yīng)用程序: 首先,創(chuàng)建一個(gè)名為pom.xml的Maven項(xiàng)目文件,添加以下內(nèi)容:idea或其他直接創(chuàng)建直接跳過(guò)!

    2024年02月09日
    瀏覽(24)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包