【发布时间】:2017-04-06 22:03:54
【问题描述】:
我已经使用 Spring Cloud Config Server 设置了一个简单的项目,我正在尝试简单地加密和解密一些值。我使用以下 pom.xml 和 Spring Boot 将项目创建为 Spring Starter Project。
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.oreilly.cloud</groupId>
<artifactId>spring-microservices-config-server6</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-microservices-config-server6</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.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>
</project>
从那里我修改主 Spring Boot Application 类以添加 @EnableConfigServer 注释,如下所示:
@SpringBootApplication
@EnableConfigServer
public class SpringMicroservicesConfigServer6Application {
public static void main(String[] args) {
SpringApplication.run(SpringMicroservicesConfigServer6Application.class, args);
}
}
在我的 application.properties 文件中,我指向一个 git 存储库,设置服务器端口并使用 encrypt.key 启用对称密钥加密,如下所示:
server.port=8888
spring.cloud.config.server.git.uri=C:/Users/training/Desktop/sts-workspace/configuration
encrypt.key=secret
接下来我打开一个 bash shell 并加密一些数据:
$ curl http://localhost:8888/encrypt -d Kevin
产生值:
`315ca5592635e4f65e0a0278cd08f74b5cef27e8379bd0e0d81d08c9ed8fbac161d`
如果我尝试使用以下方法解密该值:
$ curl localhost:8888/decrypt --data-urlencode 315ca5592635e4f65e0a0278cd08f74cef27e8379bd0e0d81d08c9ed8fbac161d
我收到以下错误:
276description":"Text not encrypted with this key","status":"INVALID"}
我不明白为什么这个简单的场景开箱即用就失败了。手动需要的配置非常少,我想知道这是否是配置服务器的问题?有人可以帮忙吗?
【问题讨论】:
-
如果有特殊字符,你只需要
--data-urlencode。如果我只使用-d,它就可以工作。 -
实际上,我错过了
-,--data-urlencode对我来说也很好。 -
@spencergibb 介意分享您的项目吗?都不适合我
-
我在使用 Camden.SR3 时遇到了同样的问题。找到原因了吗?
标签: spring spring-cloud spring-cloud-config