【问题标题】:Spring Cloud Config- Decryption of properties is not working on Client SideSpring Cloud Config-属性的解密在客户端不起作用
【发布时间】:2018-07-29 07:30:39
【问题描述】:

我有一个配置客户端和配置服务器的基本设置(与此处的教程完全相同-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

【问题讨论】:

  • 你在客户端配置好密钥了吗?
  • 重现问题的样本会有所帮助。
  • 刚刚更新了我的帖子,为我的错误缩进道歉:)
  • 你可以在不指定不应该需要的依赖项中的配置服务器版本的情况下尝试它。您也可以将代码放在 GitHub 上的存储库中吗?
  • 你是说尤里卡服务器吗?上面的 pom 是一个配置客户端 pom。

标签: java spring-boot spring-cloud spring-cloud-config


【解决方案1】:

所以,这就是解决它的方法。我添加了以下属性-

          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

【讨论】:

  • 也许您可以向文档提交 PR 并附上您建议的更改。
  • 好的。很快就会做。
猜你喜欢
  • 2017-10-23
  • 2017-01-21
  • 2021-04-13
  • 2018-08-28
  • 2021-01-13
  • 2019-02-19
  • 2020-07-19
  • 2019-07-09
  • 1970-01-01
相关资源
最近更新 更多