【Sharding Sphere、Spring Boot】Spring Boot整合Sharding Sphere Jdbc(5.0.0):数据加密

本文详细介绍了如何在SpringBoot中整合ShardingSphere 5.0.0实现数据加密,包括创建数据表、配置数据源、启用数据加密规则,并展示了测试用例。同时,讲解了通过SPI自定义加密算法的过程,包括创建Sha256Encryptor和Sha256RandomEncryptor,并在配置文件中应用。

一、Sharding Sphere基本介绍

官网链接推荐:跳转官网 | 5.0.0中文文档 | 数据加密介绍

二、环境准备

-- auto-generated definition
create table t_user
(
    user_id           varchar(32)  not null comment '用户id'
        primary key,
    user_name         varchar(255) null comment '用户名称',
    password_show     varchar(255) null comment '密码明文',
    password_encrypt  varchar(255) null comment '密码密文',
    password_assisted varchar(255) null comment '辅助查询列'
)
    comment 'Sharding Sphere数据加密测试' collate = utf8mb4_bin;

三、Spring Boot整合Sharding Sphere Jdbc实现数据加密

1、引入pom.xml依赖

		 <!--sharding-jdbc-->
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
            <version>5.0.0</version>
        </dependency>

2、application.yml配置文件


# ShardingSphere 数据加密
spring:
  shardingsphere:
    datasource:
      # 数据源
      names: master
      # 主库
      master:
        driver-class-name: com.mysql.cj.jdbc.Driver
        jdbc-url: jdbc:mysql://localhost:7000/cyun_sharding_sphere?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
        username: root
        password: root
        type: com.zaxxer.hikari.HikariDataSource
    # 使用模式,支持三种模式:内存模式、单机模式、集群模式
    mode:
      type: Memory
    props
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值