spring cloud config 加密使用

[b]spring cloud config 加密使用[/b]

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

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

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


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


[img]http://dl2.iteye.com/upload/attachment/0125/7607/7eb03157-2223-3ab5-bd00-22a774f2e493.png[/img]


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


[img]http://dl2.iteye.com/upload/attachment/0125/7611/f8ae09a6-abbb-36ee-9cb3-876628b08612.png[/img]


[b]git 上文件内容更新为[/b]
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帐号密码
spring.cloud.config.server.git.username=596134920@qq.com
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);
}

}



[img]http://dl2.iteye.com/upload/attachment/0125/7613/c7602a27-2a50-3a09-b97c-e38f9d236476.png[/img]

http://localhost:8888/encrypt/status

curl http://localhost:8888/encrypt -d 123456
curl http://localhost:8888/decrypt -d dda7913d685b9201241907150244ed055c2f69d6f6bb6d21ddbf1764ce070fbc
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jie310600

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值