SpringCloud-分布式配置中心【加密-非对称加密】

非对称加密

===================================================================

一、什么是非对称加密(Asymmetric encryption)


在这里插入图片描述

在这里插入图片描述

二、Java-keytool 使用说明


非对称加密我们需要生成对应的公钥和私钥,jdk中提供的有java-keytool工具帮助我们生成,执行如下命令:

keytool -genkeypair -alias “config-info” -keyalg “RSA” -keystore c:\tools\encryp-info.keystore

在这里插入图片描述

在这里插入图片描述

三、创建服务项目

======================================================================

1.创建项目


创建一个SpringCloud项目

在这里插入图片描述

2.pom文件


<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”>

4.0.0

org.springframework.boot

spring-boot-starter-parent

1.5.13.RELEASE

com.bobo

config-server-encryption-SRA

0.0.1-SNAPSHOT

org.springframework.cloud

spring-cloud-dependencies

Dalston.SR1

pom

import

org.springframework.boot

spring-boot-starter-web

org.springframework.cloud

spring-cloud-starter-eureka

org.springframework.cloud

spring-cloud-config-server

org.springframework.boot

spring-boot-maven-plugin

3.配置文件


spring.application.name=config-server-encryption-SRA

server.port=9060

#设置服务注册中心地址,指向另一个注册中心

eureka.client.serviceUrl.defaultZone=http://dpb:123456@eureka1:8761/eureka/,http://dpb:123456@eureka2:8761/eureka/

#Git 配置

spring.cloud.config.server.git.uri=https://gitee.com/dengpbs/config

#spring.cloud.config.server.git.username=

#spring.cloud.config.server.git.password=

#keytool -genkeypair -alias “config-info” -keyalg “RSA” -keystore c:\tools\encryp-info.keystore

keystore 文件的路径

encrypt.key-store.location=classpath:encryp-info.keystore

alias 指定密钥对的别名,该别名是公开的;

encrypt.key-store.alias=config-info

storepass 密钥仓库

encrypt.key-store.password=123456

keypass 用来保护所生成密钥对中的私钥

encrypt.key-store.secret=123456

将生成的keystore文件拷贝到classpath目录下

在这里插入图片描述

4.启动测试


测试加密状态:http://localhost:9060/encrypt/status

在这里插入图片描述

加密

public class Test1 {

/**

  • 通过RestTemplate来加密数据

  • @param args

*/

public static void main(String[] args) {

String url = “http://127.0.0.1:9060/encrypt”;

RestTemplate template = new RestTemplate();

ResponseEntity msg = template.postForEntity(url, “123456”, String.class);

System.out.println(msg.getBody());

}

}

四、创建客户端项目

=======================================================================

1.创建项目


拷贝上个案例的客户端程序。

在这里插入图片描述

2.pom文件


<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”>

4.0.0

org.springframework.boot

spring-boot-starter-parent

1.5.13.RELEASE

com.bobo

config-e-book-product-provider-sra

0.0.1-SNAPSHOT

org.springframework.boot

spring-boot-starter-web

org.mybatis.spring.boot

mybatis-spring-boot-starter

1.3.4

org.springframework.boot

spring-boot-starter-test

test

org.springframework.cloud

spring-cloud-starter-eureka

mysql

mysql-connector-java

5.1.47

com.bobo

e-book-product-service

0.0.1-SNAPSHOT

org.springframework.cloud

spring-cloud-starter-config

  • 24
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值