Kev*_*sox 5 spring spring-cloud spring-cloud-config
我已经使用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>
Run Code Online (Sandbox Code Playgroud)
从那里,我修改主Spring Boot Application类以添加@EnableConfigServer注释,如下所示:
@SpringBootApplication
@EnableConfigServer
public class SpringMicroservicesConfigServer6Application {
public static void main(String[] args) {
SpringApplication.run(SpringMicroservicesConfigServer6Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的application.properties文件中,我指向一个git存储库,设置服务器端口并使用encrypt.key以下方式启用对称密钥加密:
server.port=8888
spring.cloud.config.server.git.uri=C:/Users/training/Desktop/sts-workspace/configuration
encrypt.key=secret
Run Code Online (Sandbox Code Playgroud)
接下来,我打开一个bash shell并加密一些数据:
$ curl http://localhost:8888/encrypt -d Kevin
Run Code Online (Sandbox Code Playgroud)
产生值:
`315ca5592635e4f65e0a0278cd08f74b5cef27e8379bd0e0d81d08c9ed8fbac161d`
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用以下方法解密值:
$ curl localhost:8888/decrypt --data-urlencode 315ca5592635e4f65e0a0278cd08f74cef27e8379bd0e0d81d08c9ed8fbac161d
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
276description":"Text not encrypted with this key","status":"INVALID"}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这种简单的方案几乎立即失败了。手动需要的配置非常少,我想知道这是否与配置服务器有关?有人可以帮忙吗?
我刚刚发现发生了什么事:
$ curl -X POST localhost:8888/encrypt -d FOO
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 67 100 64 100 3 4000 187 --:--:-- --:--:-- --:--:-- 4000e474cd78d6c18e0e5395e67a3bc0865a75077650e91d2249d460e91d6989ce87
Run Code Online (Sandbox Code Playgroud)
我将其4000e474cd78d6c18e0e5395e67a3bc0865a75077650e91d2249d460e91d6989ce87作为加密文本,但无法正常工作。
问题在于“当前速度”列就在响应之前,因此我们正在使用它,就像它是响应的一部分一样。
实际的密文是删除当前速度: e474cd78d6c18e0e5395e67a3bc0865a75077650e91d2249d460e91d6989ce87
$ curl localhost:8888/decrypt -d e474cd78d6c18e0e5395e67a3bc0865a75077650e91d2249d460e91d6989ce87
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 67 100 3 100 64 187 4000 --:--:-- --:--:-- --:--:-- 4000FOO
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1352 次 |
| 最近记录: |