spring cloud config 加密使用

spring cloud config 加密使用

数据不加密放在git上的比较危险的
加密后就可以让config server 进行解密,这样会比较安全

下载Java 8 JCE(默认使用的是有长度限制的版本,所以要用这个)
http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

其实就是将JDK/jre/lib/security目录中的两个jar文件替换为JCE中的jar文件。


curl 工具安装
在官网处下载工具包: http://curl.haxx.se/download.html





当然,可以给Windows增加curl命令的环境变量,增加CURL_HOME环境变量,给PATH环境变量加上%CURL_HOME%; 
这样就可以在命令窗口的任意目录下使用curl命令了。






git 上文件内容更新为
configClient-test.properties

#cipher 表明是加密过的
foo = {cipher}dda7913d685b9201241907150244ed055c2f69d6f6bb6d21ddbf1764ce070fbc





<?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.midea</groupId>
	<artifactId>base</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>jar</packaging>
	<name>base</name>


	<!-- 设定仓库,按设定顺序进行查找. -->
	<!--<repositories> <repository> <id>public</id> <name>Team Nexus Repository</name> 
		<url>http://10.33.183.113:8081/nexus/content/groups/public</url> <snapshots> 
		<enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> 
		</repository> </repositories> <pluginRepositories> <pluginRepository> <id>public</id> 
		<name>Team Nexus Repository</name> <url>http://10.33.183.113:8081/nexus/content/groups/public</url> 
		<snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> 
		</pluginRepository> </pluginRepositories> -->

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.2.RELEASE</version>
	</parent>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>Dalston.SR1</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-config</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</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>

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

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

		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka</artifactId>
		</dependency>

		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>2.4.0</version>
			<exclusions>
				<exclusion>
					<groupId>org.slf4j</groupId>
					<artifactId>slf4j-api</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger-ui</artifactId>
			<version>2.4.0</version>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-log4j2</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>
	<build>

	</build>
</project>






server.port=8888


#服务器路径
#server.context-path=/eurekaServer

spring.application.name=config-server

#gitHub路径
spring.cloud.config.server.git.uri=https://github.com/huangyongxing310/springCloudConfigTest.git
#文件路径,如果是根目录可以不配置
spring.cloud.config.server.git.searchPaths=test
#配置仓库的分支,
spring.cloud.config.label=master
#gitHub帐号密码
[email protected]
spring.cloud.config.server.git.password=xing310600

#security安全机制
security.user.name=user
security.user.password=123456

eureka.client.serviceUrl.defaultZone=http://localhost:8761/eurekaServer/eureka/

# 设置对称密钥
encrypt.key=123456



package com;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;



@SpringBootApplication //spring boot 开启应用
@EnableConfigServer //表示开启Config服务
@EnableEurekaClient //只能为eureka作用
public class Application {

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}

}






http://localhost:8888/encrypt/status

curl http://localhost:8888/encrypt -d 123456
curl http://localhost:8888/decrypt -d dda7913d685b9201241907150244ed055c2f69d6f6bb6d21ddbf1764ce070fbc






猜你喜欢

转载自huangyongxing310.iteye.com/blog/2382002