基于Sharding Sphere实现数据“一键脱敏”
以下文章来源方志朋的博客,回复”666“获面试宝典
来源:https://jaskey.github.io/blog/2020/03/18/sharding-sphere-data-desensitization/
在真实业务场景中,数据库中经常需要存储某些客户的关键性敏感信息如:身份证号、银行卡号、姓名、手机号码等,此类信息按照合规要求,通常需要实现加密存储以满足合规要求。
痛点一:
通常的解决方案是我们书写SQL的时候,把对应的加密字段手动进行加密再进行插入,在查询的时候使用之前再手动进行解密。此方法固然可行,但是使用起来非常不便捷且繁琐,使得日常的业务开发与存储合规的细节紧耦合
痛点二:
对于一些为了快速上线而一开始没有实现合规脱敏的系统,如何比较快速的使得已有业务满足合规要求的同时,尽量减少对原系统的改造。(通常的这个过程至少包括:1.新增脱敏列的存储 2.同时做数据迁移 3.业务的代码做兼容逻辑等)。
Apache ShardingSphere下面存在一个数据脱敏模块,此模块集成的常用的数据脱敏的功能。其基本原理是对用户输入的SQL进行解析拦截,并依靠用户的脱敏配置进行SQL的改写,从而实现对原文字段的加密及加密字段的解密。最终实现对用户无感的加解密存储、查询。
脱敏配置Quick Start——Spring 显示配置:
以下介绍基于Spring如何快速让系统支持脱敏配置。
1.引入依赖
<!-- for spring namespace -->
<dependency><groupId>org.apache.shardingsphere</groupId><artifactId>sharding-jdbc-spring-namespace</artifactId><version>${sharding-sphere.version}</version>
</dependency>
2.创建脱敏配置规则对象
在创建数据源之前,需要准备一个EncryptRuleConfiguration进行脱敏的配置,以下是一个例子,对于同一个数据源里两张表card_info,pay_order的不同字段进行AES的加密
private EncryptRuleConfiguration getEncryptRuleConfiguration() {
Properties props = new Properties();//自带aes算法需要
props.setProperty("aes.key.value", aeskey);
EncryptorRuleConfiguration encryptorConfig = new EncryptorRuleConfiguration("AES", props);//自定义算法
//props.setProperty("qb.finance.aes.key.value", aeskey);
//EncryptorRuleConfiguration encryptorConfig = new EncryptorRuleConfiguration("QB-FINANCE-AES", props);EncryptRuleConfiguration encryptRuleConfig = new EncryptRuleConfiguration();
encryptRuleConfig.getEncryptors().put("aes", encryptorConfig);//START: card_info 表的脱敏配置
{EncryptColumnRuleConfiguration columnConfig1 = new EncryptColumnRuleConfiguration("", "name", "", "aes");EncryptColumnRuleConfiguration columnConfig2 = new EncryptColumnRuleConfiguration("", "id_no", "", "aes");EncryptColumnRuleConfiguration columnConfig3 = new EncryptColumnRuleConfiguration("", "finshell_card_no", "", "aes");Map<String, EncryptColumnRuleConfiguration> columnConfigMaps = new HashMap<>();columnConfigMaps.put("name", columnConfig1);columnConfigMaps.put("id_no", columnConfig2);columnConfigMaps.put("finshell_card_no", columnConfig3);EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration(columnConfigMaps);encryptRuleConfig.getTables().put("card_info", tableConfig);
}
//END: card_info 表的脱敏配置//START: pay_order 表的脱敏配置
{EncryptColumnRuleConfiguration columnConfig1 = new EncryptColumnRuleConfiguration("", "card_no", "", "aes");Map<String, EncryptColumnRuleConfiguration> columnConfigMaps = new HashMap<>();columnConfigMaps.put("card_no", columnConfig1);EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration(columnConfigMaps);encryptRuleConfig.getTables().put("pay_order", tableConfig);
}log.info("脱敏配置构建完成:{} ", encryptRuleConfig);
return encryptRuleConfig;
}
说明:
创建 EncryptColumnRuleConfiguration 的时候有四个参数,前两个参数分表叫plainColumn、cipherColumn,其意思是数据库存储里面真实的两个列(名文列、脱敏列),对于新的系统,只需要设置脱敏列即可,所以以上示例为plainColumn为”“。
创建EncryptTableRuleConfiguration 的时候需要传入一个map,这个map存的value即#1中说明的EncryptColumnRuleConfiguration ,而其key则是一个逻辑列,对于新系统,此逻辑列即为真实的脱敏列。Sharding Shpere在拦截到SQL改写的时候,会按照用户的配置,把逻辑列映射为名文列或者脱敏列(默认)如下的示例
3.使用Sharding Sphere的数据源进行管理
把原始的数据源包装一层
@Bean("tradePlatformDataSource") public DataSource dataSource(@Qualifier("druidDataSource") DataSource ds) throws SQLException { return EncryptDataSourceFactory.createDataSource(ds, getEncryptRuleConfiguration(), new Properties()); }
脱敏配置Quick Start——Spring Boot版:
以下步骤使用Spring Boot管理,可以仅用配置文件解决:
1.引入依赖
<!-- for spring boot --><dependency>
<groupId>org.apache.shardingsphere</groupId><artifactId>sharding-jdbc-spring-boot-starter</artifactId><version>${sharding-sphere.version}</version>
</dependency><!-- for spring namespace -->
<dependency><groupId>org.apache.shardingsphere</groupId><artifactId>sharding-jdbc-spring-namespace</artifactId><version>${sharding-sphere.version}</version>
</dependency>
2.Spring 配置文件
spring.shardingsphere.datasource.name=ds
spring.shardingsphere.datasource.ds.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.ds.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds.url=xxxxxxxxxxxxx
spring.shardingsphere.datasource.ds.username=xxxxxxx
spring.shardingsphere.datasource.ds.password=xxxxxxxxxxxx# 默认的AES加密器
spring.shardingsphere.encrypt.encryptors.encryptor_aes.type=aes
spring.shardingsphere.encrypt.encryptors.encryptor_aes.props.aes.key.value=hkiqAXU6Ur5fixGHaO4Lb2V2ggausYwW# card_info 姓名 AES加密
spring.shardingsphere.encrypt.tables.card_info.columns.name.cipherColumn=name
spring.shardingsphere.encrypt.tables.card_info.columns.name.encryptor=encryptor_aes# card_info 身份证 AES加密
spring.shardingsphere.encrypt.tables.card_info.columns.id_no.cipherColumn=id_no
spring.shardingsphere.encrypt.tables.card_info.columns.id_no.encryptor=encryptor_aes# card_info 银行卡号 AES加密
spring.shardingsphere.encrypt.tables.card_info.columns.finshell_card_no.cipherColumn=finshell_card_no
spring.shardingsphere.encrypt.tables.card_info.columns.finshell_card_no.encryptor=encryptor_aes# pay_order 银行卡号 AES加密
spring.shardingsphere.encrypt.tables.pay_order.columns.card_no.cipherColumn=card_no
spring.shardingsphere.encrypt.tables.pay_order.columns.card_no.encryp
热门内容:60岁还在写代码的开发者,他的建议或许正是你现在焦虑的根源!尝试改变一下吧!Java必会的工具库,让你的代码量减少90%我终于决定要放弃 okhttp、httpClient,选择了这个牛逼的神仙工具!贼爽重磅!干掉Dubbo,又干掉Spring Cloud,阿里正式拥抱这个神级Java框架!字符串拼接还在用StringBuilder?快试试Java8中的StringJoiner吧,真香!最近面试BAT,整理一份面试资料《Java面试BAT通关手册》,覆盖了Java核心技术、JVM、Java并发、SSM、微服务、数据库、数据结构等等。获取方式:点“在看”,关注公众号并回复 666 领取,更多内容陆续奉上。
明天见(。・ω・。)ノ♡
基于Sharding Sphere实现数据“一键脱敏”相关推荐
- Sharding Sphere实现数据“一键脱敏”
痛点一: 通常的解决方案是我们书写SQL的时候,把对应的加密字段手动进行加密再进行插入,在查询的时候使用之前再手动进行解密.此方法固然可行,但是使用起来非常不便捷且繁琐,使得日常的业务开发与存储合规的 ...
- 基于FME实现不动产数据一键导出自然资源部汇交格式
基于FME实现不动产数据一键导出 自然资源部汇交格式 自2015年中华人民共和国国务院令第656号签<不动产登记条例施行>施行.各省市区县在2017年相继成立不动产登记机构,整合原有国土 ...
- 实现数据“一键脱敏”,Sharding Sphere帮你搞定
以下文章来源方志朋的博客,回复"666"获面试宝典 在真实业务场景中,数据库中经常需要存储某些客户的关键性敏感信息如:身份证号.银行卡号.姓名.手机号码等,此类信息按照合规要求,通 ...
- Springboot 日志、配置文件、接口数据如何脱敏?老鸟们都是这样玩的!
一.前言 核心隐私数据无论对于企业还是用户来说尤其重要,因此要想办法杜绝各种隐私数据的泄漏.下面陈某带大家从以下三个方面讲解一下隐私数据如何脱敏,也是日常开发中需要注意的: 配置文件数据脱敏 接口返回 ...
- RM: 基于页面结构化数据生成报表,一键导出图片,生成定制图表 文末有效果图 , 开放部分代码
背景 开发这个工具是因为一句抱怨 故事是这样的,我们公司是一个非常重视员工健康的公司,一年前老董说让HR(后面改为ZT)督促员工多多运动,可持续地位公司创造价值.并拿出了一部预算来奖励那些积极运动的人 ...
- 敏感数据,“一键脱敏”,Sharding Sphere 完美搞定
来源:https://jaskey.github.io/blog/2020/03/18/sharding-sphere-data-desensitization/Jaskey Lam 在真实业务场景中 ...
- 如何基于java代理对大数据缓存组件返回的数据进行脱敏和阻断
如何基于java代理对大数据缓存组件返回的数据进行脱敏和阻断 背景 架构拓扑图 实现方式对比 UDF方案 优点: 缺点: 改写返回结果方案 优点: 缺点: 说明 实现 默认处理方式 redis报文解析 ...
- Sharding Sphere 与 Lcn事务区别
Sharding Sphere http://shardingsphere.apache.org/index_zh.html 两阶段事务-XA 两阶段事务提交采用的是X/OPEN组织所定义的DTP模型 ...
- 巨杉数据库TechDay回顾 | 分布式数据库@民生、Sharding Sphere@京东、ClickHouse@微博
大数据时代,数据早已成为全球战略资源级的存在,数据库也成为了所有应用成功运行的核心.同时,随着创新业务的不断增加,业务的复杂及庞大的体量必然会产生错综复杂且规模巨大的结构化数据,这些都迫使企业对数据库 ...
最新文章
- 将matlab的.m文件打包为独立可执行程序.exe —— 基于Matlab R2015b
- 2013\Province_C_C++_A\3.振兴中华
- c#中字节数组byte[]、图片image、流stream,字符串string、内存流MemoryStream、文件file,之间的转换
- 5186. 区间内查询数字的频率
- Jumpserver web界面跳板机
- nginx+lua+redis实现post请求接口之黑名单(一)
- 全网疯传的PDF干货合集,50个精选BAT等大厂大数据、算法落地经验,白拿不谢!...
- 麻省理工18年春软件构造课程阅读07“设计规格说明”
- 如何用PS把背景完全扣掉,变成透明
- 【python爬虫】每日获取强智教务系统课表,并发送短信到学生手机
- Excel:表格中重复项的处理
- outlook邮箱pc/mac客户端下载 含最新版
- Linux 服务器配置使用密钥登录教程
- 爱在深秋-稻城亚丁旅游途中的风花雪月
- lstm 文本分类_带有lstm和单词嵌入的灾难推文上的文本分类
- 模拟法螺旋遍历矩阵:54.螺旋矩阵(Kotlin)
- zjs-my-dary-20220113
- 世界经典科幻影片TOP20
- 国家海洋局的超算应用探索
- 王道考研b站操作系统、计算机组成原理、计算机网络课程(课件资料)
热门文章
- kettle中三种类型: 增量不裁剪,增量裁剪,全量
- Idea--使用Idea调试设置
- Boring counting HDU - 3518 (后缀数组)
- 学习笔记53—Wilcoxon检验和Mann-whitney检验的区别
- [网络流24题] 最长k可重区间集
- 分布式技术一周技术动态 2016-11-27
- 日期处理工具类 -【二】
- 随笔,记2014忆往昔岁月
- 【译】使用自定义ViewHelper来简化Asp.net MVC view的开发------part1
- Love Java , Love IBM , Love Sun ( SunJiHai )