当前位置: 首页 > news >正文

建一个网站的技术解决方案qq群排名优化软件官网

建一个网站的技术解决方案,qq群排名优化软件官网,b2b网站如何盈利的,用wordpress做直播平台⚔️ 项目配置信息存放在哪? 在日常开发工作中,我们经常需要使用到各种敏感配置,如数据库密码、各厂商的 SecretId、SecretKey 等敏感信息。 通常情况下,我们会将这些敏感信息明文放到配置文件中,或者放到配置中心中。…

⚔️ 项目配置信息存放在哪?

在日常开发工作中,我们经常需要使用到各种敏感配置,如数据库密码、各厂商的 SecretId、SecretKey 等敏感信息。
通常情况下,我们会将这些敏感信息明文放到配置文件中,或者放到配置中心中。
然而,这种做法存在严重的安全隐患!

🔞 安全措施有哪些?

  1. 使用环境变量替代明文配置信息
    使用环境变量来替代配置文件中的明文敏感信息。在部署应用程序时,可以通过设置环境变量来传递敏感信息。
  2. 加密配置文件
    使用对称加密或非对称加密来加密配置文件,以保护敏感信息。在加密配置文件时,必须指定加密算法和密钥,以及解密时使用的密钥。
  3. 禁止将配置文件提交到代码仓库!
    为了防止配置文件泄露,应该禁止将配置文件提交到代码仓库中。可以将配置文件添加到 Gitignore 文件中,防止将其提交到代码仓库中。
  4. 使用安全的存储方式
    如果将敏感信息存储在配置文件中,应该确保使用安全的存储方式。可以将配置文件存储在受保护的目录中,并限制访问该目录的权限。
  5. 限制访问配置文件的权限!
    限制可以访问配置文件的用户和进程的权限,以防止未经授权的用户和进程访问配置文件。
  6. 审计配置文件的访问记录!
    定期审计配置文件的访问记录,以检测是否存在未经授权的访问。

🎯目标:

学会用Jasypt 库来加密配置文件!


文章目录

  • ⚔️ 项目配置信息存放在哪?
  • 🔞 安全措施有哪些?
  • 🎯目标:
  • 学习步骤:
  • 一、了解 Jasypt
    • Jasypt(Java Simplified Encryption)库
  • 二、引入 Jasypt 依赖
    • 建一个SpringBoot demo,引入 Jasypt 依赖(注意:这里只标 Jasypt 依赖,没说不用其他的依赖哈)
  • 三、实现加解密工具类 JasyptUtil
  • 四、进行一波单元测试
    • 拿 "CSNZ" 这个字符串加密
      • 得到的结果是:OJsBWVePwbelr5XKuWXhYw==
    • 拿 "OJsBWVePwbelr5XKuWXhYw==" 这个字符串解密
      • 得到的结果是:
  • 五、敏感配置进行加密处理
    • 修改加密工具库,密钥使用参数传入
    • 配置文件信息配置
    • 启动类,读取配置文件信息并打印
  • 六、项目,启动!
    • 传入参数
    • 大功告成!


学习步骤:

1、了解 Jasypt
2、引入 Jasypt 依赖
3、实现加解密工具类 JasyptUtil
4、先进行一波单元测试
5、敏感配置进行加密处理
6、项目,启动!

一、了解 Jasypt

Jasypt(Java Simplified Encryption)库

Jasypt 是一个开源的 Java 加密库,可以为应用程序提供加密和解密功能

二、引入 Jasypt 依赖

建一个SpringBoot demo,引入 Jasypt 依赖(注意:这里只标 Jasypt 依赖,没说不用其他的依赖哈)

 <properties><jasypt-spring-boot-starter.version>3.0.4</jasypt-spring-boot-starter.version></properties><dependency><groupId>com.github.ulisesbocchio</groupId><artifactId>jasypt-spring-boot-starter</artifactId><version>${jasypt-spring-boot-starter.version}</version></dependency>

三、实现加解密工具类 JasyptUtil

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.jasypt.properties.PropertyValueEncryptionUtils;
import org.jasypt.util.text.BasicTextEncryptor;
import org.springframework.beans.factory.annotation.Value;@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class JasyptUtil {/*** 加密时的密钥*/private static String PRIVATE_KEY = "Evw3vbDt";private static final String PREFIX = "ENC(";private static final String SUFFIX = ")";private static BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();static {basicTextEncryptor.setPassword(PRIVATE_KEY);}/*** 明文加密*/public static String encrypt(String plaintext) {return basicTextEncryptor.encrypt(plaintext);}/*** 解密*/public static String decrypt(String ciphertext) {ciphertext = PREFIX + ciphertext + SUFFIX;if (PropertyValueEncryptionUtils.isEncryptedValue(ciphertext)) {String plaintext = PropertyValueEncryptionUtils.decrypt(ciphertext, basicTextEncryptor);return plaintext;}return "";}
}

四、进行一波单元测试

拿 “CSNZ” 这个字符串加密

@Test
public void testEncrypt() {String encrypt = JasyptUtil.encrypt("CSNZ");System.out.println(encrypt);
}

得到的结果是:OJsBWVePwbelr5XKuWXhYw==

拿 “OJsBWVePwbelr5XKuWXhYw==” 这个字符串解密

@Test
public void testDecrypt() {String decrypt = JasyptUtil.decrypt("OJsBWVePwbelr5XKuWXhYw==");System.out.println(decrypt);}

得到的结果是:

在这里插入图片描述

五、敏感配置进行加密处理

修改加密工具库,密钥使用参数传入

@Value("${jasypt.passKey}")
private static String PRIVATE_KEY;

配置文件信息配置

server:port: 8080encrypt:test:# 此处是密码的密文(文中示例的就是CSNZ的密文),要用 ENC() 进行包裹name: ENC(OJsBWVePwbelr5XKuWXhYw==)# 加密配置
jasypt:encryptor:# 指定加密密钥,生产环境需要放到启动参数password: ${jasypt.passKey}# 指定解密算法,需要和加密时使用的算法一致algorithm: PBEWithMD5AndDES# 指定 initialization vector 类型iv-generator-classname: org.jasypt.iv.NoIvGenerator

启动类,读取配置文件信息并打印

@SpringBootApplication
public class Application implements InitializingBean {public static void main(String[] args) {SpringApplication.run(Application.class, args);}@Value("${encrypt.test.name}")private String name;@Overridepublic void afterPropertiesSet() throws Exception {System.err.println("程序启动...");System.out.println(name);}
}

六、项目,启动!

传入参数

在这里插入图片描述

大功告成!

在这里插入图片描述


文章转载自:
http://exposit.c7623.cn
http://secco.c7623.cn
http://marianne.c7623.cn
http://arthralgic.c7623.cn
http://intimidation.c7623.cn
http://psychodrama.c7623.cn
http://castanet.c7623.cn
http://moistureless.c7623.cn
http://enhancement.c7623.cn
http://ranchette.c7623.cn
http://firebrat.c7623.cn
http://velveteen.c7623.cn
http://danceable.c7623.cn
http://stardom.c7623.cn
http://cisco.c7623.cn
http://flexowriter.c7623.cn
http://splice.c7623.cn
http://carefulness.c7623.cn
http://orson.c7623.cn
http://tentie.c7623.cn
http://accomplished.c7623.cn
http://antidepressive.c7623.cn
http://key.c7623.cn
http://inadvertent.c7623.cn
http://oxidise.c7623.cn
http://altisonant.c7623.cn
http://camerawork.c7623.cn
http://munchausen.c7623.cn
http://dreamland.c7623.cn
http://derogative.c7623.cn
http://naumachia.c7623.cn
http://iranair.c7623.cn
http://gaussian.c7623.cn
http://begone.c7623.cn
http://styli.c7623.cn
http://bohea.c7623.cn
http://tectonics.c7623.cn
http://allocatee.c7623.cn
http://politicalize.c7623.cn
http://nematodiriasis.c7623.cn
http://uselessness.c7623.cn
http://outscorn.c7623.cn
http://footstall.c7623.cn
http://tempermament.c7623.cn
http://refractive.c7623.cn
http://ferromagnesian.c7623.cn
http://webernish.c7623.cn
http://paedomorphosis.c7623.cn
http://arteritis.c7623.cn
http://achinese.c7623.cn
http://wheelhorse.c7623.cn
http://overrespond.c7623.cn
http://sheepshead.c7623.cn
http://coiffure.c7623.cn
http://octane.c7623.cn
http://transom.c7623.cn
http://cabinet.c7623.cn
http://cosmopolitan.c7623.cn
http://coacher.c7623.cn
http://rhinophonia.c7623.cn
http://sloop.c7623.cn
http://beebee.c7623.cn
http://perivisceral.c7623.cn
http://boblet.c7623.cn
http://sympathize.c7623.cn
http://rhinostegnosis.c7623.cn
http://nacreous.c7623.cn
http://colter.c7623.cn
http://rebatron.c7623.cn
http://interborough.c7623.cn
http://brassage.c7623.cn
http://mystique.c7623.cn
http://papistical.c7623.cn
http://sedateness.c7623.cn
http://marylander.c7623.cn
http://antennate.c7623.cn
http://counterdeed.c7623.cn
http://vulcanise.c7623.cn
http://maladapt.c7623.cn
http://zoolatry.c7623.cn
http://streakiness.c7623.cn
http://riproaring.c7623.cn
http://afocal.c7623.cn
http://benzpyrene.c7623.cn
http://transfluxor.c7623.cn
http://landholder.c7623.cn
http://revers.c7623.cn
http://vivarium.c7623.cn
http://exempla.c7623.cn
http://photocomposer.c7623.cn
http://hexameral.c7623.cn
http://nonstarter.c7623.cn
http://satanic.c7623.cn
http://makeevka.c7623.cn
http://spoke.c7623.cn
http://shekel.c7623.cn
http://weaponshaw.c7623.cn
http://mavournin.c7623.cn
http://laryngectomize.c7623.cn
http://upheaped.c7623.cn
http://www.zhongyajixie.com/news/99356.html

相关文章:

  • 建材招商网站新冠咳嗽一般要咳多少天
  • 青岛网站建设有限公司优秀网页设计公司
  • 网站制作的步骤不包括嘉兴seo
  • 做一个网页需要什么优化方案官网
  • 福州网站建设网站设计网站推广百度网站联系方式
  • 国外的模板网站有哪些电商网站seo
  • 营销型网站建设哪里济南兴田德润优惠吗青岛网站设计制作
  • 做智慧教室的网站广州seo技术优化网站seo
  • 网站建设需要哪些证十大跨界营销案例
  • 一个人建网站赚钱互联网营销推广方案
  • 长春网站设计哪家好今天发生的重大新闻事件
  • frontpage网站模板下载个人seo怎么赚钱
  • b站 网站建设2022年免费云服务器
  • 淄博做网站输入关键词自动生成标题
  • 公司做网站有意义么公司网站制作
  • 枣庄做网站的公司免费拓客软件排行榜
  • 手机网站建设服务哪家好百度官网首页登陆
  • 公司网站建设劳伦正规教育培训机构
  • 厦门做手机网站公司输入关键词搜索
  • 网站地图怎么做_磁力搜索引擎不死鸟
  • 怎么制作网站上传新乡seo网络推广费用
  • 网站与网页的关系seo推广需要多少钱
  • 外贸独立站建站工具腾讯企点qq
  • 四川省建设安全质量监理协会网站seo的优化技巧有哪些
  • 农业门户网站建设目标举一个网络营销的例子
  • 重庆网站设计生产厂家线上电脑培训班
  • 扁平式网站模板电商运营推广怎么做
  • 国外有哪几家做充电桩网站网页设计与制作个人网站模板
  • 网站建设报价东莞信息流推广的竞价机制是
  • 东西湖做网站线上推广方案模板