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}

相关推荐
while(1){yan}20 小时前
MyBatis Generator
数据库·spring boot·java-ee·mybatis
memgLIFE1 天前
mybatis数据库查询
数据库·oracle·mybatis
drebander1 天前
MyBatis-Plus saveBatch 在异步线程中事务未提交问题排查与修复
数据库·mybatis
super_lzb1 天前
mybatis拦截器ResultSetHandler详解
java·spring·mybatis·springboot
七夜zippoe1 天前
ORM框架下的SQL优化 N+1问题识别与解决方案
自动化·mybatis·jpa·n+1·batch fetching
Yu_iChan1 天前
苍穹外卖Day09 地址簿模块
java·数据库·mybatis
雁凡彡2 天前
mybatis-plus中sqlserver 查询数组中指定位置前的数据
数据库·sqlserver·mybatis
alonewolf_992 天前
Spring整合Mybatis底层源码深度解析:从@MapperScan到SQL执行的完整流程
spring·mybatis
小肖爱笑不爱笑2 天前
JDBC Mybatis
数据库·mybatis
while(1){yan}2 天前
图书管理系统(超详细版)
spring boot·spring·java-ee·tomcat·log4j·maven·mybatis