首页 > 其他分享 >Mybatis-plus 数据安全保护

Mybatis-plus 数据安全保护

时间:2022-09-20 17:35:46浏览次数:70  
标签:username AES String System randomKey plus 数据安全 Mybatis out

1、加密前 application-dev.yml

spring:
  datasource:
    url: jdbc:p6spy:mysql://localhost:3306/mybatis_plus?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
    username: xxxx
    password: xxxx
    driver-class-name: com.p6spy.engine.spy.P6SpyDriver

 2、生成秘钥 RandomKeyTest.java

public class RandomKeyTest {
    @Test
    public void createRodomKey() {
        // 生成 16 位随机 AES 密钥
        String randomKey = AES.generateRandomKey();
        System.out.println(randomKey);//7a10eda6bd25ae0c// 随机密钥加密
        String url = AES.encrypt("jdbc:mysql://localhost:3306/mybatis_plus?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai", randomKey);
        System.out.println(url);
        String username = AES.encrypt("xxxx", randomKey);
        System.out.println(username);
        String pwd = AES.encrypt("xxxx", randomKey);
        System.out.println(pwd);
    }
}
7a10eda6bd25ae0c
i7i+PzJiQwvMnuJ0MJXaaP/qBbi9Aje+DS4BA5nsKxzl8ffrqzs3twtkXdylhANQrmFkiAyGSXy7ab09hioajGzcxllb8vuxycgX73776NCQvz3Iba3M+b8GgPwNuqR/BJp6a4iXNrNriFhWQltF7w==
6/dktUCf5WgciJud7DHWPA==
6/dktUCf5WgciJud7DHWPA==

3、秘钥替换 application-pro.yml

spring:
  datasource:
    url: mpw:i7i+PzJiQwvMnuJ0MJXaaP/qBbi9Aje+DS4BA5nsKxzl8ffrqzs3twtkXdylhANQrmFkiAyGSXy7ab09hioajGzcxllb8vuxycgX73776NCQvz3Iba3M+b8GgPwNuqR/BJp6a4iXNrNriFhWQltF7w==
    username:  mpw:6/dktUff5WgciJud7DHWPA==
    password:  mpw:rk/neE9036346Rz68Tpa6Q==
    driver-class-name: com.mysql.cj.jdbc.Driver

4、如何使用:

//将项目打成jar包,使用pro.xml执行
> java -jar project.jar --mpw.key=7a10eda6bd25ae0c  --spring.profiles.active=pro

 

标签:username,AES,String,System,randomKey,plus,数据安全,Mybatis,out
From: https://www.cnblogs.com/xiaozhaoboke/p/16711795.html

相关文章