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}"
}
}
spring:
cloud:
config:
server:
git:
uri: https://gitlab.some.domain/somerepo.git
encrypt:
key: key_instance
(不加该注解也可实现加解密功能)
@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
Spring Cloud Config(统一配置中心服务端和客户端)
【开发经验】springboot配置文件加密详解
SpringBoot 配置文件这样加密,才足够安全!
jasypt对springboot配置文件加密解密及在测试加密解密中遇到的坑
云服务器运行报错Value for key ‘PROMPT_COMMAND‘ could not be loaded using ‘com.ulisesbocchio.jasyptspringboot
JASYPT with Spring Boot problem encrypt strong password and using it in the app