Springboot - druid 数据库密码加密

cpp 复制代码
    private static String publicKey;
    private static String privateKey;

    static {
        try {
            String[] keyPair = ConfigTools.genKeyPair(512);
            privateKey = keyPair[0];
            System.out.println("privateKey:" + privateKey);
            publicKey = keyPair[1];
            System.out.println("publicKey:" + publicKey);
        } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
            e.printStackTrace();
        }
    }

    public static String encrypt(String plainText) throws Exception {
        String encrypt = ConfigTools.encrypt(privateKey, plainText);
        System.out.println("encryptA:" + encrypt);
        return encrypt;
    }

    public static String decrypt(String encryptText) throws Exception {
        String decrypt = ConfigTools.decrypt(publicKey, encryptText);
        System.out.println("decrypt:" + decrypt);
        return decrypt;
    }

    public static void main(String[] args) throws Exception {
       String encrypt= encrypt("root");
        System.out.println("encrypt"+encrypt);
    }
cpp 复制代码
spring:
  datasource:
    username: root
    password: TbsMfMeo1+B5Zl2+IrUN8hnW+4pqrOWnNT1xYWoAEjjWdlwReT4CPefxUhKLJwycKvOsBpk+RPS36clXJ2t/OA== #加密后的密码
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/jrlyt_sub?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      connectionProperties: config.decrypt=true;config.decrypt.key=${publicKey}; #公钥自动扫描
    filter:
      config:
        enabled: true #开启属性是扫描
#加密公钥
publicKey: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIWFBfwNmjK5qo7c7A0ao1TdxcC0+porCS4A9C2KNgp4dKVNBGyEqXJNSYDn4JrtXw2SYLV4OkHDPM2x9Mh8hYMCAwEAAQ==
相关推荐
virus59456 小时前
悟空CRM mybatis-3.5.3-mapper.dtd错误解决方案
java·开发语言·mybatis
没差c7 小时前
springboot集成flyway
java·spring boot·后端
时艰.7 小时前
Java 并发编程之 CAS 与 Atomic 原子操作类
java·开发语言
编程彩机8 小时前
互联网大厂Java面试:从Java SE到大数据场景的技术深度解析
java·大数据·spring boot·面试·spark·java se·互联网大厂
笨蛋不要掉眼泪8 小时前
Spring Boot集成LangChain4j:与大模型对话的极速入门
java·人工智能·后端·spring·langchain
Yvonne爱编码8 小时前
JAVA数据结构 DAY3-List接口
java·开发语言·windows·python
像少年啦飞驰点、9 小时前
零基础入门 Spring Boot:从“Hello World”到可上线微服务的完整学习指南
java·spring boot·微服务·编程入门·后端开发
眼眸流转9 小时前
Java代码变更影响分析(一)
java·开发语言
Yvonne爱编码9 小时前
JAVA数据结构 DAY4-ArrayList
java·开发语言·数据结构
阿猿收手吧!9 小时前
【C++】C++原子操作:compare_exchange_weak详解
java·jvm·c++