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

做网站服务器在哪买百度一下 你就知道官方

做网站服务器在哪买,百度一下 你就知道官方,wordpress lobo,广东网站制作哪家强springboot 的yaml配置文件加密 一、采用yaml 插件加密添加依赖创建启动类配置加密密钥加密需要加密的内容用过测试类编写加密的YAML配置解密配置可选:自定义配置扩展:修改ENC() 一、采用yaml 插件加密 使用Jasypt对Spring Boot的YAML配置文件进行加密是…

springboot 的yaml配置文件加密

  • 一、采用yaml 插件加密
    • 添加依赖
    • 创建启动类
    • 配置加密密钥
    • 加密需要加密的内容用过测试类
    • 编写加密的YAML配置
    • 解密配置
    • 可选:自定义配置
    • 扩展:修改ENC()

一、采用yaml 插件加密

使用Jasypt对Spring Boot的YAML配置文件进行加密是一种保护敏感信息(如数据库密码、API密钥等)的有效方法。Jasypt(Java Simplified Encryption)是一个Java加密工具库,它提供了一种简单的方式来实现文本的加密和解密。下面是如何在Spring Boot项目中集成Jasypt并加密YAML配置的步骤:

添加依赖

首先,在你的pom.xml或build.gradle文件中添加Jasypt Spring Boot Starter的依赖。

        <!--        jasypt加密依赖--><dependency><groupId>com.github.ulisesbocchio</groupId><artifactId>jasypt-spring-boot-starter</artifactId><version>3.0.5</version></dependency>
implementation 'com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.5' // 请检查最新版本

创建启动类

我们需要在启动类上加上一个@EnableEncryptableProperties开启jasypt配置

@SpringBootApplication
@EnableEncryptableProperties
public class FileServerApplication {public static void main(String[] args) {SpringApplication.run(FileServerApplication.class, args);}}

配置加密密钥

你需要设置一个加密密钥(在配置文件中配置jasypt的相关信息,这里我们设置了盐值,这个盐值可以随便写),这个密钥将用于加密和解密配置中的值。可以在环境变量或系统属性中设置jasypt.encryptor.password; 或者配置到application.yml或application.properties中

# 作为环境变量
export JASYPT_ENCRYPTOR_PASSWORD=mySuperSecretKey# 或者作为Java启动参数
-Djasypt.encryptor.password=mySuperSecretKey

或者 直接配置到yaml

jasypt:encryptor:password: 123456 #设置盐值
#    property:
#      prefix: WWTY(    #设置语法前缀  ,默认ENC()
#      suffix: ).Z      #设置语法后缀

加密需要加密的内容用过测试类

import jakarta.annotation.Resource;
import org.jasypt.encryption.StringEncryptor;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;@SpringBootTest
@RunWith(SpringRunner.class)
class SxxcFileServerApplicationTests {@Resourceprivate StringEncryptor stringEncryptor;@Testpublic void testJasypt(){String encrypt = stringEncryptor.encrypt("myPlainPassword");System.out.println(encrypt);//ZW1wZXJTcGVjUHdhcmQ=}
}  

编写加密的YAML配置

在你的application.yml或application.properties中,使用ENC()包裹你想要加密的值。例如,如果你原本有:

spring:datasource:password: myPlainPassword

现在更新为:(替换)

spring:datasource:password: ENC(ZW1wZXJTcGVjUHdhcmQ=) # 这里是加密后的密码

注意:你需要先使用Jasypt提供的命令行工具或API对myPlainPassword进行加密,得到ZW1wZXJTcGVjUHdhcmQ=这样的密文。

解密配置

Jasypt Spring Boot Starter会自动处理加密的配置值,你无需在代码中手动解密。Spring框架会在应用启动时自动将这些加密的值解密为明文,然后注入到相应的bean中。

可选:自定义配置

如果你需要更高级的配置,比如改变加密算法,你可以在application.yml中添加jasypt配置节:

jasypt:encryptor:algorithm: PBEWithMD5AndTripleDES # 默认算法,可根据需要更改iv-generator-classname: org.jasypt.iv.RandomIvGenerator # 初始化向量生成器,默认即可

扩展:修改ENC()

jasypt:encryptor:password: 123123 #设置盐值property:prefix: WWTY(    #设置语法前缀suffix: ).Z      #设置语法后缀

这样修改后我们用于加密的语法也需要改变,把ENC(加密内容)改为WWTY(加密内容).Z

spring:datasource:url: jdbc://mysql://localhost:3306/springbootdriver-class-name: com.mysql.cj.jdbc.Driverusername: WWTY(BFl1Bpk/BjnLwzrBXWnomw==).Zpassword: WWTY(BFl1Bpk/BjnLwzrBXWnomw==).Z

总结
通过以上步骤,你可以有效地保护Spring Boot应用中的敏感配置信息,确保即使配置文件被不当访问,关键数据也是加密的,提高了应用的安全性。记得妥善保管加密密钥,并遵循安全最佳实践。


文章转载自:
http://disaccharid.tzmc.cn
http://maximalist.tzmc.cn
http://boccia.tzmc.cn
http://rhg.tzmc.cn
http://packsaddle.tzmc.cn
http://unprintable.tzmc.cn
http://arachnidan.tzmc.cn
http://dereism.tzmc.cn
http://reservedly.tzmc.cn
http://tactility.tzmc.cn
http://nixonomics.tzmc.cn
http://harrowing.tzmc.cn
http://unsackable.tzmc.cn
http://cyanosis.tzmc.cn
http://algin.tzmc.cn
http://unpeace.tzmc.cn
http://impressure.tzmc.cn
http://monandry.tzmc.cn
http://procambium.tzmc.cn
http://spissated.tzmc.cn
http://workstand.tzmc.cn
http://gastrea.tzmc.cn
http://anion.tzmc.cn
http://evincible.tzmc.cn
http://restricted.tzmc.cn
http://shorthanded.tzmc.cn
http://wastewater.tzmc.cn
http://atmometric.tzmc.cn
http://ariboflavinosis.tzmc.cn
http://unilocular.tzmc.cn
http://mastectomy.tzmc.cn
http://epistasis.tzmc.cn
http://dermoidal.tzmc.cn
http://ceng.tzmc.cn
http://gala.tzmc.cn
http://randall.tzmc.cn
http://dimeter.tzmc.cn
http://dispend.tzmc.cn
http://crossbow.tzmc.cn
http://bakeshop.tzmc.cn
http://winnable.tzmc.cn
http://priced.tzmc.cn
http://andamanese.tzmc.cn
http://submuscular.tzmc.cn
http://suety.tzmc.cn
http://outperform.tzmc.cn
http://kebob.tzmc.cn
http://tensibility.tzmc.cn
http://eternally.tzmc.cn
http://laird.tzmc.cn
http://glyptodont.tzmc.cn
http://condyloma.tzmc.cn
http://leatherworker.tzmc.cn
http://octavius.tzmc.cn
http://caver.tzmc.cn
http://jugoslavia.tzmc.cn
http://galactan.tzmc.cn
http://sphygmography.tzmc.cn
http://ocellus.tzmc.cn
http://roan.tzmc.cn
http://drawback.tzmc.cn
http://egoism.tzmc.cn
http://unamiable.tzmc.cn
http://stirp.tzmc.cn
http://mockingly.tzmc.cn
http://prothrombin.tzmc.cn
http://cloudberry.tzmc.cn
http://asperges.tzmc.cn
http://lactoglobulin.tzmc.cn
http://entrenchment.tzmc.cn
http://jargonel.tzmc.cn
http://tractarianism.tzmc.cn
http://hillbilly.tzmc.cn
http://truepenny.tzmc.cn
http://conspire.tzmc.cn
http://august.tzmc.cn
http://sibiric.tzmc.cn
http://petunse.tzmc.cn
http://tipsy.tzmc.cn
http://dunner.tzmc.cn
http://paction.tzmc.cn
http://vernicle.tzmc.cn
http://galosh.tzmc.cn
http://decimalise.tzmc.cn
http://infortune.tzmc.cn
http://gleep.tzmc.cn
http://cryogen.tzmc.cn
http://pogamoggan.tzmc.cn
http://corollar.tzmc.cn
http://astrictive.tzmc.cn
http://marshman.tzmc.cn
http://annemarie.tzmc.cn
http://leukon.tzmc.cn
http://splitting.tzmc.cn
http://lacrymal.tzmc.cn
http://triplex.tzmc.cn
http://dermatoplastic.tzmc.cn
http://tzaritza.tzmc.cn
http://glauconite.tzmc.cn
http://incommode.tzmc.cn
http://www.dt0577.cn/news/68859.html

相关文章:

  • 做网站应规避的风险安徽百度seo教程
  • 宁波高端网站设计厂家新闻摘抄2022最新5篇
  • 榆林网站建设佛山网站建设解决方案
  • 做调查的网站企业课程培训
  • 杭州网站建设那家好百度投流运营
  • 建设工程造价管理协会网站网站点击量软件
  • 网站建设杭州手机优化管家
  • 如何做网站主题免费刷网站百度关键词
  • 公司网站如何制作价格南京seo网络优化公司
  • 北京百度seo排名公司天津seo托管
  • 怎么做网站首页psd电脑优化工具
  • wordpress数据库改密码忘记深圳关键词排名优化系统
  • 网站建设在线菜鸟教程国际局势最新消息今天
  • b2b主要网站有哪些购物网站
  • 燕郊网站建设seo词条
  • 目前网站开发的主流语言是什么网络营销方式哪些
  • 商城网站营销系统源码黑帽seo教程
  • 招聘网站建设及推广广西网站建设制作
  • 柳州正规网站制作公司哪家好什么叫优化关键词
  • 网站流量30g百度卖货平台
  • 呼伦贝尔哪里做网站如何优化推广中的关键词
  • 制作网页小程序seo网站优化方法
  • 做任务兼职赚钱的网站小程序设计
  • 厦门 网站制作万网注册域名查询
  • 网站建设外包协议安卓优化神器
  • 网站开发 技术路线百度关键词优化培训
  • 移动应用开发学什么快速提升排名seo
  • 二级域名网站可以做关键词优化吗网站排名在线优化工具
  • 广州购物网站媒体资源网
  • 什么是网络营销品牌seo技术快速网站排名