当前位置: 首页 > 知识库问答 >
问题:

无法从Spring配置服务器/cleint解密

麹高义
2023-03-14

我正在尝试使用Spring配置服务器和客户端加密和解密配置属性。我有Spring启动应用程序(服务器和客户端),使用服务器我有加密的密码属性,在客户端,我试图使用相同的密钥解密它,但出错了。我正在尝试启用配置服务器客户端来解密这些最初由配置服务器加密的属性。以下是我遵循的步骤:

> < li>

安装全强度JCE并替换JRE lib/security中的2个策略文件

使用keytool生成密钥

keytool -genkeypair -alias config-server-key -keyalg RSA \
-keysize 4096 -sigalg SHA512withRSA -dname "CN=*.domain.com,OU=EUS,O=eusdom,L=City,S=WA,C=US" \
-keypass keyPass -keystore config-server.jks -storepass keys3crt

向pom文件添加了云安全依赖项(在配置服务器和客户端pom中都添加了这些依赖项)

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-rsa</artifactId>
<version>1.0.1.RELEASE</version>
</dependency>

将加密相关配置(配置服务器和客户端使用的相同值)添加到bootstrap.yml也尝试使用application.yml

encrypt:
key-store:
    location: file:///D:/encrypt-server/config-server.jks
    password: keyPass
    alias: config-server-key
    secret: keys3crt

我的配置服务器引导程序如下所示

spring:
  application:
    name: config-service
  cloud:
    config:
        server:
            git:
                uri: https://github.com/<>/spring-config-repo
            encrypt:
                enabled: false
server:
  port: 8888

使用配置服务器加密passWord属性

curl -X POST --data-urlencode d3v3L \  http://localhost:8888/encrypt

尝试使用配置服务器解密属性

curl  http://localhost:8888/decrypt  -d <encryptedVale>

我收到以下错误。

    {"timestamp":1472667297292,"status":500,"error":"Internal Server Error","exception":"java.lang.IllegalStateException","message":"Cannot decrypt","path":"/decrypt"}

我尝试使用config客户端打印加密的属性(注意:我已经按照3,4添加了依赖项并加密密钥详细信息)

@RefreshScope
@Component
@RestController
public class Greeter {

@Value("${cassandra.hostnames}")
String hostnames;

@Value("${cassandra.username}")
String userName;

@Value("${cassandra.password}")
String passWord;

@RequestMapping(value = "/", produces = "application/json")
public List<String> index(){
    List<String> env = Arrays.asList(
        "userName is: " + userName,
        "passWord is: " + passWord,
);
return env;
}

}

我收到< code > Java . lang . illegalstateexception:无法解密:key=cassandra.password错误

注意:我尝试在没有的情况下在配置服务器中解密

 encrypt:
  enabled: false

如果我在这里遗漏了什么,请告诉我。感谢任何帮助。

共有1个答案

蒯坚白
2023-03-14

默认情况下,不再启用用于启用非对称加密的引导配置。如果您的项目需要它,可以通过属性或新启动者重新启用它。可以在这里找到指导方针[1]:https://github.com/spring-cloud/spring-cloud-release/wiki/Spring-Cloud-2020.0-Release-Notes#breaking-更改

要在大于2.3.x的Spring Boot版本中启用引导,我们需要添加#SpringCloud引入的新的初始依赖项。

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bootstrap</artifactId>
        <version>3.0.1</version>
    </dependency>
 类似资料:
  • 使用@value(${fanout.exchange})注释在使用带有Github Repo的spring-cloud-config服务器时初始化失败。我得到: 这两个类的pom.xml上都有spring-cloud-config。configServer使用@EnableConfigServer进行注释。我在github repo中的文件名为datacollector.properties Ra

  • 当我试图启动SpringBoot主应用程序时,出现以下异常。为什么我会得到这个特例。 异常: Spring boot主java类

  • 我正在关注应用程序中的条目。 我有下面的spring云服务器应用程序代码。 我收到以下错误。 启动ApplicationContext时出错。要显示条件报告,请在启用“调试”的情况下重新运行应用程序。2021 02月24日01:39:52.356错误20804---[restartedMain]o.s.b.d.LoggingFailureAnalysisReporter: 应用程序无法启动 描述:

  • 错误: > 连客户端都没有启动 http://localhost:8080/ 将spring.config.import=configServer:属性添加到您的配置中。如果不需要配置,则添加spring.config.import=optional:configserver:。要禁用此检查,请设置spring.cloud.config.enabled=false或spring.cloud.con

  • 我一直在尝试掌握位于此处的spring boot config服务器:https://github.com/spring-cloud/spring-cloud-config在更彻底地阅读了文档之后,我能够解决我的大部分问题。然而,我不得不为基于文件的PropertySourceLocator编写一个额外的类 然后我将其添加到ConfigServiceBootstrapConfiguration.j

  • 我正在使用Spring Cloud Config服务器,能够检测来自git存储库的更改并将其传递给配置客户机。 有两种方法,我已经实现了: null 所以两者都工作得很好,那么使用Spring Cloud Bus有什么好处吗?或者在生产环境中,不使用Spring Cloud Bus会有什么问题吗?因为将需要额外的工作来设置RabbitMQ集群(HA)作为生产中的Spring云总线。 谢谢,大卫