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}

相关推荐
indexsunny1 天前
互联网大厂Java面试实战:Spring Boot、MyBatis与Kafka在电商场景中的应用
java·spring boot·面试·kafka·mybatis·电商·技术栈
神の愛1 天前
mybatis什么时候不走 缓存??
spring·缓存·mybatis
小哇6662 天前
MybatisPlus-JSON类型处理器 存取 数据库的JSON 字段数据
mybatis
難釋懷2 天前
缓存同步
spring·缓存·mybatis
阿丰资源2 天前
SpringBoot+MySQL+MyBatis-Plus+Vue前后端分离仓库管理系统 (附资料)
spring boot·mysql·mybatis
等....2 天前
Redis使用
数据库·redis·mybatis
卓怡学长3 天前
m326数据结构课程网络学习平台的设计与实现+vue
java·spring·tomcat·maven·intellij-idea·mybatis