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

Spring Boot 配置文件加密

方式一:Spring Cloud Config

一、建立config server

1. build.gradle 文件中添加:

plugins {id 'java'id 'org.springframework.boot' version '2.7.0'id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}ext {set('springCloudVersion', "2021.0.8")
}dependencies {implementation 'org.springframework.cloud:spring-cloud-config-server'// 不加该依赖无法调用 /encrypt 和 /decrypt 接口:implementation 'org.springframework.cloud:spring-cloud-starter-config'
}dependencyManagement {imports {mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"}
}

2. application.yaml 文件中添加:

  • 存放配置文件的git仓库。可以是git remote repo,也可以是local repo(file://…)
spring:cloud:config:server:git:uri: https://gitlab.some.domain/somerepo.git
  • 加解密的密钥
encrypt:key: key_instance

3. Application 启动类添加 @EnableConfigServer 注解:

(不加该注解也可实现加解密功能)

@EnableConfigServer
@SpringBootApplication
public class DemoApplication {...
}

二、获得加密后的密文

获得加密后的密文:

$ curl http://localhost:8080/encrypt -d id111
7b04915ff83caae96116140fe180be4b9a217fbdaf4c3d38263c2479819d5202

获得解密后的明文:

$ curl http://localhost:8080/decrypt -d 7b04915ff83caae96116140fe180be4b9a217fbdaf4c3d38263c2479819d5202
id111

三、将加密后的密文添加进配置文件

application.yaml 文件中添加:

  • 加密后的密文
    id: '{cipher}7b04915ff83caae96116140fe180be4b9a217fbdaf4c3d38263c2479819d5202'
    

启动后项目中的id属性会自动解密为“id111"。

Spring Cloud Config 配置的加密解密
分布式配置中心Spring Cloud Config初窥
Spring Cloud Config

SpringCloud与SpringBoot的版本适配

建立 config client:

Spring Cloud Config(统一配置中心服务端和客户端)

方式二:jasypt

【开发经验】springboot配置文件加密详解
SpringBoot 配置文件这样加密,才足够安全!

http://www.lryc.cn/news/154028.html

相关文章:

  • 【树形权限】树形列表权限互斥选择、el-tree设置禁用等等
  • ubuntu 22.04安装cuda、cudnn、conda、pytorch
  • 2023 最新前端面试题 (HTML 篇)
  • 华为云银河麒麟V10安装libmcrypt
  • 智慧导览|智能导游系统|AR景区导览系统|景区电子导览
  • 【Docker】Docker基本使用介绍
  • Linux命令200例:man用于显示和阅读关于Linux内置命令的使用说明
  • idea 无法识别maven的解决
  • String底层函数的实现方式
  • uniapp实现微信小程序全局可分享功能
  • 大数据成为市场营销利器 ,促进金融贷款企业获客精准化
  • Acwing 3472. 八皇后
  • Word转为PDF后图片模糊怎么办?Word转为PDF的技巧介绍
  • 【django开发手册】详解drf filter中DjangoFilterBackend,SearchFilter,OrderingFilter使用方式
  • 3D开发工具HOOPS Publish如何快速创建交互式3D PDF文档?
  • 【Kafka】ZooKeeper启动失败报错java.net.BindException: Address already in use: bind
  • 系统架构设计师-计算机系统基础知识(1)
  • Mediasoup在node.js下多线程实现
  • 一文入门Web网站安全测试
  • Django REST framework中的序列化Serializers
  • LeetCode 剑指 Offer 10- I. 斐波那契数列
  • Css 将某div设置为透明,但其子元素不透明
  • 17 | Spark中的map、flatMap、mapToPair mapvalues 的区别
  • 手写Mybatis:第9章-细化XML语句构建器,完善静态SQL解析
  • 云原生Kubernetes:Kubeadm部署K8S单Master架构
  • 鸿鹄工程项目管理系统em Spring Cloud+Spring Boot+前后端分离构建工程项目管理系统
  • 开发指导—利用 CSS 动画实现 HarmonyOS 动效(二)
  • 音频修复和增强工具 iZotope RX 10 for mac激活最新
  • SpringMVC的简介及工作流程
  • JVM垃圾回收机制和常用算法(简洁版)