Spring Cloud構成サーバーを使用して簡単なプロジェクトをセットアップしましたが、一部の値を単純に暗号化および復号化しようとしています。 Springブートで次のpom.xmlを使用して、プロジェクトをSpring Starterプロジェクトとして作成します。Spring Cloud構成対称鍵
の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>
そこから、私は次のよう@EnableConfigServer
注釈を追加するには、メインの春ブーツApplicationクラスを変更します。
@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シェルを開いて、いくつかのデータ暗号化:値を生成
$ 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'を使うだけで動作します。 – spencergibb
実際、私は '-'、' --data-urlencode'も私にとってうまく働いていませんでした。 – spencergibb
@spencergibbはあなたのプロジェクトを共有していますか?どちらも動作しません –