微服务SpringCloud—Config Server对称加密
配置内容的加解密
在Git仓库中明文存储配置属性的。很多场景下,对于某些敏感的配置内容(例如数据库账号、密码等),应当加密存储。
Config对称加解密
1、安装JCE
默认情况下我们的JRE自带了JCE,但是默认是一个有限长度的版本,需要到oracle官网下载一个不限长度的JCE。
JCE下载地址
https://www.oracle.com/technetwork/java/javase/downloads/jce-all-download-5170447.html
下载JCE并解压(eg:jce_policy-8.zip),按照其中的README.txt的说明安装。
JCE的安装非常简单,其实就是将JDK/jre/lib/security目录中的两个jar文件(local_policy.jar、US_export_policy.jar)替换为压缩包中的jar文件。
2、在config server服务的bootstrap.yml文件中配置对称密匙
#博客:https://blog.csdn.net/u014296316/article/details/80881974
#http://localhost:6063/encrypt/status 验证加密解密功能是否正常
#http://localhost:6063/encrypt 只允许post请求
#http://localhost:6063/decrypt 只允许post请求
encrypt:
key: Lynch
3、访问 http://localhost:6063/encrypt/status 验证加密解密功能是否正常
4、访问/encrypt和/decrypt进行加密解密
http://localhost:6063/encrypt 只允许post请求
http://localhost:6063/decrypt 只允许post请求
5、配置文件中使用{cipher}开头标识加密数据
6、在Config Client服务获取加密数据
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; /**
* 这边的@RefreshScope注解不能少,否则即使调用/refresh,配置也不会刷新
*/
@RestController
@RefreshScope
public class ConfigClientController { @Value("${env}")
private String env; @Value("${password}")
private String password; @Value("${username}")
private String username; @GetMapping("/config/profile")
public String hello() {
return this.env+","+this.password+","+this.username;
}
}
http://localhost:6062/config/profile
微服务SpringCloud—Config Server对称加密的更多相关文章
- SpringCloud与微服务Ⅹ --- SpringCloud Config分布式配置中心
一.SpringCloud Config是什么 分布式系统面临的问题 --- 配置问题 微服务意味着要将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中会出现大量的服务.由于每个 ...
- 「 从0到1学习微服务SpringCloud 」06 统一配置中心Spring Cloud Config
系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」01 一起来学呀! 「 从0到1学习微服务SpringCloud 」02 Eureka服务注册与发现 「 从0到1学习微服务S ...
- 微服务SpringCloud之配置中心和消息总线
在微服务SpringCloud之Spring Cloud Config配置中心SVN博客中每个client刷新配置信息时需要post请求/actuator/refresh,但客户端越来越多时,,需要每 ...
- 「 从0到1学习微服务SpringCloud 」10 服务网关Zuul
系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」06 统一配置中心Spring Cloud Config 「 从0到1学习微服务SpringCloud 」07 RabbitM ...
- springcloud情操陶冶-springcloud config server(三)
承接前文springcloud情操陶冶-springcloud config server(二),本文就不讲述server了,就简单阐述下client的应用 前话 config server在引入的时 ...
- Java生鲜电商平台-深入理解微服务SpringCloud各个组件的关联与架构
Java生鲜电商平台-深入理解微服务SpringCloud各个组件的关联与架构 概述 毫无疑问,Spring Cloud是目前微服务架构领域的翘楚,无数的书籍博客都在讲解这个技术.不过大多数讲解还停留 ...
- 小D课堂 - 新版本微服务springcloud+Docker教程_汇总
小D课堂 - 新版本微服务springcloud+Docker教程_1_01课程简介 小D课堂 - 新版本微服务springcloud+Docker教程_1_02技术选型 小D课堂 - 新版本微服务s ...
- 「 从0到1学习微服务SpringCloud 」09 补充篇-maven父子模块项目
系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」06 统一配置中心Spring Cloud Config 「 从0到1学习微服务SpringCloud 」07 RabbitM ...
- 「 从0到1学习微服务SpringCloud 」08 构建消息驱动微服务的框架 Spring Cloud Stream
系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」01 一起来学呀! 「 从0到1学习微服务SpringCloud 」02 Eureka服务注册与发现 「 从0到1学习微服务S ...
随机推荐
- Windows linux子系统 使用说明
1.安装 linux 子系统 2.应用商店安装ubuntu 3.为了方便可以配置成默认登陆root账户 Ubuntu config –default-user root 4. 安装完毕 5.安 ...
- Numpy 基础运算2
# -*- encoding:utf-8 -*- # Copyright (c) 2015 Shiye Inc. # All rights reserved. # # Author: ldq < ...
- iOS 获取app进程被杀死事件
程序被用户双击上滑杀死后,就对app做一些特殊的处理 下面的方法可以获取到用户双击上滑杀死的事件 - (void)applicationDidEnterBackground:(UIApplicatio ...
- Oracle、DB2、SQLSERVER、Mysql、Access分页SQL语句
最近把平时在项目中常用到的数据库分页sql总结了下.大家可以贴出分页更高效的sql语句.sqlserver分页 第一种分页方法 需用到的参数: pageSize 每页显示多少条数据 pageNu ...
- FCC学习笔记(三)
Using Objects for Lookups // 定义 phoneticLookupfunction phoneticLookup(val) { var result = "&quo ...
- LeetCode第五十八题
题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return t ...
- Mysql初学入门
最近研究了一下Mysql的初学应用,在此进行整理记录. 1.Windows系统下的安装 我用的是win10系统,在http://dev.mysql.com/downloads/mysql/ 下载相应版 ...
- linux学习:网络(防火墙)及系统安全相关命令学习
指令: top.htop.free.pstree.lsof.ifconfig.w3m.tcpdump.netstat.nmap.ufw 网络: top #查看内存,cpu,进程之间的状态.hto ...
- QT中foreach的使用
在标准C++中,并没有foreach关键字. 但是在QT中,可以使用这一个关键字,其主要原因是QT自己增加了这一个关键字,就像slots和signals.emit等一样.增加的foreach关键字在编 ...
- 【kafka学习之五】kafka运维:kafka操作日志设置和主题删除
一.操作日志 首先附上kafka 操作日志配置文件:log4j.properties 根据相应的需要设置日志. #日志级别覆盖规则 优先级:ALL < DEBUG < INFO <W ...