SharedingSphere 自定义脱敏规则介绍

文档地址:Yaml配置 :: ShardingSphere

官方默认的脱敏

SharedingSphere 自定义脱敏规则介绍_第1张图片

可以看出使用的Type是aes算法、

我们怎么实现自己的自定义规则呢

1. 实现接口

org.apache.shardingsphere.encrypt.strategy.spi.Encryptor; 

SharedingSphere 自定义脱敏规则介绍_第2张图片

2. 修改yml配置文件

SharedingSphere 自定义脱敏规则介绍_第3张图片

这里加密type写成自己自定义的,随意都可以的。

然后在自己的实现类中将Type添加进来。

SharedingSphere 自定义脱敏规则介绍_第4张图片

编写init方法

SharedingSphere 自定义脱敏规则介绍_第5张图片

private final static String TYPE = "custom-aes"; 
    private static final String SHARDING_PROPERTIES = "properties/sharding.properties"; 
    private Properties properties; 
    @Override
    public void init() {
        try {
            properties = PropertiesLoaderUtils.loadAllProperties(SHARDING_PROPERTIES);
        } catch (IOException e) {
            log.error("读取sharding配置文件失败," + e.getMessage(), e);
            throw new RuntimeException("读取sharding配置文件失败," + e.getMessage(), e);
        } 
    }

初始完成之后我们将 Properties get/set 方法实现。

SharedingSphere 自定义脱敏规则介绍_第6张图片

接下来就是最重要的环节了,那就是自定义加解密规则。

SharedingSphere 自定义脱敏规则介绍_第7张图片

这里实现方式自己自定义实现即可。

对了,文档中还说了ase.key.value,这个值我们可以定义在Properties文件中,然后读取进来。

这个方法是在我们自定义加密的的key 。

最后要将我们自定义的文件包路径配置到springboot的自动装配路径下。

SharedingSphere 自定义脱敏规则介绍_第8张图片

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

你可能感兴趣的:(SharedingSphere 自定义脱敏规则介绍)