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==
相关推荐
零度@6 小时前
Java 消息中间件 - ActiveMQ 保姆级全解2026
java·activemq·java-activemq
weixin_399380696 小时前
TongWeb异常宕机问题分析
java·tomcat
小鸡脚来咯6 小时前
设计模式面试介绍指南
java·开发语言·单例模式
怦怦蓝6 小时前
详解 IntelliJ IDEA 中编写邮件发送功能(从环境搭建到实战落地)
java·spring boot·intellij-idea
DENG8623046 小时前
二、使用idea运行Quarkus项目及调试
java·intellij-idea·quarkus
sww_10266 小时前
Spring AI Structured-Output源码分析
java·人工智能·spring
IT_Octopus6 小时前
java 实体属性 Map 解决 mybatis-plus wrapper selectone 查mysql json类型为null 问题
java·mysql·mybatis
我的golang之路果然有问题6 小时前
Docker 之常用操作(实习中的)
java·运维·笔记·docker·容器·eureka