集成 MybatisPlus 数据安全保护
该功能为了保护数据库配置及数据安全,在一定的程度上控制开发人员流动导致敏感信息泄露
package com.ruoyi.extend.configsecurity;
import com.baomidou.mybatisplus.core.toolkit.AES;
/**
* MybatisPlus 数据安全保护
*
* @author Tellsea
* @date 2022/9/3
*/
public class DataSecurityTest {
public static void main(String[] args) {
// 生成 16 位随机 AES 密钥
String randomKey = AES.generateRandomKey();
// 随机密钥加密
System.out.println("随机密钥:" + randomKey);
String url = "jdbc:mysql://127.0.0.1:3306/ruoyi-vue-service?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
String username = "root";
String password = "123456";
System.out.println("url: mpw:" + AES.encrypt(url, randomKey));
System.out.println("username: mpw:" + AES.encrypt(username, randomKey));
System.out.println("password: mpw:" + AES.encrypt(password, randomKey));
}
}
生成之后的结果如下,直接复制到配置文件中
随机密钥:13999e7ab997a498
url: mpw:qTaNIyvTORcbdv5K00Bm0PSEkW2QhQRQ7qGfbWg+OxZEsh4+N7ojg1SUqMk2lolusXzEegXFpfH3f2n11N3N6Ws33dtkYN7Sg1ySRd1uQ1lWAhLLl1JDs7oM6QBbDiCTHnLnDfU2zi9xmFrVxjUXOKCJIRSPvWbkG4olkdAD8sC4Bprhb4n8H9B2bzKRDALg7Q7m9aW+EBuep4VmvdrlXQ==
username: mpw:MpkqZJ82X0adfa+KsWmuzQ==
password: mpw:Gzu2CuEX7QjN60nwUgbSgQ==
Jar 启动参数( idea 设置 Program arguments , 服务器可以设置为启动环境变量 )
--mpw.key=13999e7ab997a498