SpringBoot + MyBatisPlus实现Yaml配置参数AES算法加密

文章目录

  • SpringBoot + MyBatisPlus实现Yaml配置参数AES算法加密
    • 1概述
    • 2 密钥加密
    • 3 Yaml参数配置
    • 4 使用方式

SpringBoot + MyBatisPlus实现Yaml配置参数AES算法加密

1概述

  • 该功能为了保护数据库配置及数据安全,在一定的程度上控制开发人员流动导致敏感信息泄露。
  • MybatisPlus版本要求: 3.3.2+

2 密钥加密

// 生成 16 位随机 AES 密钥
String randomKey = AES.generateRandomKey();

// 随机密钥加密
String result = AES.encrypt(data, randomKey);

3 Yaml参数配置

  • 注意事项: 加密配置必须以 mpw: 字符串开头!!!
// 加密配置 mpw: 开头紧接加密内容(所有配置参数均可使用)
spring:
  datasource:
    url: mpw:SgzR0RIVp7tcrVAgf+KQC6XRa62hnW102m2Xd6l2asvI3TB8ZXT1YsuC79omFCvi/C1tfCQyDUDKngrIrhuQtg==
    password: mpw:npBEYOUyNaSPGiXp9/hVhQ==
    username: mpw:dwDIspd5OkIv9yIyqttPEw==

SpringBoot + MyBatisPlus实现Yaml配置参数AES算法加密_第1张图片

4 使用方式

// Jar 启动参数(idea 设置 Program arguments,服务器可以设置为启动环境变量),参数值为步骤2生成的AES 密钥
--mpw.key=e231113965db81b4

SpringBoot + MyBatisPlus实现Yaml配置参数AES算法加密_第2张图片

你可能感兴趣的:(SpringBoot,spring,boot,java,后端)