日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

配置文件的属性ENC加密

發(fā)布時間:2023/12/13 综合教程 34 生活家
生活随笔 收集整理的這篇文章主要介紹了 配置文件的属性ENC加密 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

轉(zhuǎn)載:https://www.cnblogs.com/zqyx/p/9687136.html

在micro service體系中,有了config server,我們可以把配置存放在git、svn、數(shù)據(jù)庫等,普通的web項目也基本上是把配置存放在配置文件中。如果我們把大量的配置信息都放在配置文件中是會有安全隱患的,那么如何消除這個隱患呢?最直接的方式就是把配置信息中的一些敏感信息(比如數(shù)據(jù)庫密碼、中間件密碼)加密,然后程序在獲取這些配置的時候解密,就可以達到目的。這個時候,jasypt框架就派上用場了。

Jasypt is a java library which allows the developer to add basic encryption capabilities to his/her projects with minimum effort, and without the need of having deep knowledge on how cryptography works.

High-security, standards-based encryption techniques, both for unidirectional and bidirectional encryption. Encrypt passwords, texts, numbers, binaries...
Transparent integration withHibernate.
Suitable for integration intoSpring-based applications and also transparently integrable withSpring Security.
Integrated capabilities for encrypting the configuration of applications (i.e. datasources).
Specific features forhigh-performance encryptionin multi-processor/multi-core systems.
Open API for use with any JCE provider.
...and much more

意思其實就是可以把Jasypt這個Java庫當成是一個黑盒子,無需深入了解里面怎么運作的,可以拿來直接用(當然,作為碼農(nóng)我們還是要去一探究竟的,個人興趣自己看吧)。現(xiàn)在基本上項目都集成spring boot了,因此我們可以使用jasypt-spring-boot-starter

1. 引入pom包

 <dependency>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-spring-boot-starter</artifactId>
    <version>2.0.0</version>
 </dependency>

2. 找到maven倉庫中的jasypt-1.9.2.jar(路徑是:.m2epositoryorgjasyptjasypt1.9.2

3. 調(diào)用jasypt-1.9.2.jar包中一個main方法org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI,源碼參考:

View Code

然后執(zhí)行一下語句:

java -cp jasypt-1.9.2.jar  org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="test" password=salt algorithm=PBEWithMD5AndDES

-- input參數(shù):你想要加密的密碼
-- password參數(shù):jasypt用來加密你的密碼的密碼

結(jié)果如下圖,途中的output就是加密后的密文了。

4. 修改配置文件,把配置文件中要加密的字段改為:ENC(密文)

system:
  mysql:
    url: xxx.xxx.xx.xx
    username: username
    password: ENC(qh8kixDUkvm1DIJrpLFtzw==)

jasypt:
  encryptor:
    password: salt

以上就可以達到目的。

總結(jié)

以上是生活随笔為你收集整理的配置文件的属性ENC加密的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。