我有一个配置客户端和配置服务器的基本设置(与这里的教程完全一样- https://spring.io/guides/gs/centralized-configuration/
我的问题是我可以在服务器端解密属性并将它们作为纯文本发送,但不能在客户端而不是服务器端解密属性。我正在使用对称加密,并且已经多次阅读文档但无法在客户端工作时进行解密。
我在服务器端添加了以下属性,所以它不会解密服务器端的属性-
spring.cloud.config.server.encrypt.enabled=false
我有一个包含加密值的 application.yml 文件-
name: '{cipher}hdshdghsgdhjsgdhsgdyassudyadssd2313wdw2e'
我尝试在客户端添加 ENCRYPT_KEY/encrypt.key 作为环境变量、系统属性。此外,已尝试在 application.properties 和 bootstrap.properties 中添加相同内容,但客户端无法解密。
提前致谢。
配置客户端POM-
......................................
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
................................
在配置服务器中我添加了属性-
spring.cloud.config.server.encrypt.enabled=false
在配置客户端,我在 application.properties 和 bootstrap.properties 中添加了 encrypt.key。
encrypt.key=abcd
最佳答案
所以,这就是解决问题的方法。我添加了以下属性-
spring.cloud.config.server.encrypt.enabled=false
在配置服务器端的 application.properties/yaml 中。这是错误的。需要
在 bootstrap.properties/yaml 中而不是 application.properties/yaml 中。
这可以明确地添加到文档中吗?
我确实在文档中看到了上述属性的提及,但没有看到它应该添加到的位置。
https://cloud.spring.io/spring-cloud-config/single/spring-cloud-config.html
关于java - Spring Cloud Config-属性解密在客户端不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48859810/