MyBatis-Plus的数据安全保护

文章目录


一、介绍

  • 对配置文件内容加密,3.3.2开始支持
  • 使用AES加密算法
  • 实现原理:SafetyEncryptProcessor implements EnvironmentPostProcessorSimpleCommandLinePropertySource,只有在命令行的配置源读取到mpw.key才会解密

二、生成密钥

  • 使用mybatis-plus封装的方法
java 复制代码
//16位的AES密钥
String secretKey=AES.generateRandomKey();
  • 或者自己使用AES算法生成密钥

三、加密

java 复制代码
//使用密钥、明文获取加密后的密文
String ciphertext=AES.encrypt("root",secretKey);

四、配置文件内容使用密文

yml 复制代码
spring:
    datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        # 密文内容需要添加mpw:前缀
        username: mpw:9FAXZu54/X8se+SOnzqBdQ==

五、命令行参数

  1. idea的Program arguments、jar启动的参数添加

  2. 启动命令中添加

    --mpw.key=密钥

  3. 环境变量+启动命令

    //环境变量中添加
    /etc/profile
    export MPW_KEY=密钥
    source /etc/profile

    //启动命令添加
    --mpw.key=${MPW_KEY}

相关推荐
Mcband6 小时前
MyBatis 拦截器让搞定监控、脱敏和权限控制
mybatis
╭╰4027 小时前
苍穹外卖优化-续
java·spring·mybatis
weixin_456904277 小时前
基于Spring Boot + MyBatis的用户管理系统配置
spring boot·后端·mybatis
码熔burning14 小时前
Redis 的三种高效缓存读写策略!
redis·缓存·mybatis
stein_java1 天前
Mybatis-7 XML映射器
数据库·sql·mybatis
托比-马奎尔1 天前
MyBatis入门到精通:CRUD实战指南
mybatis
ByteBlossom1 天前
MyBatis高频问题-自动映射与缓存解析
mybatis
半夏陌离1 天前
SQL 进阶指南:视图的创建与使用(视图语法 / 作用 / 权限控制)
java·数据库·mybatis
BillKu1 天前
Spring Boot中MyBatis的定义与使用
spring boot·mybatis
lozhyf1 天前
固定资产管理系统(vue+Springboot+mybatis)
vue.js·spring boot·mybatis