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==
相关推荐
sxlishaobin2 分钟前
Java I/O 模型详解:BIO、NIO、AIO
java·开发语言·nio
彭于晏Yan8 分钟前
Spring AI(二):入门使用
java·spring boot·spring·ai
有一个好名字22 分钟前
vibe codeing 开发流程
java
兑生28 分钟前
【灵神题单·贪心】3745. 三元素表达式的最大值 | 排序贪心 | Java
java·开发语言
polaris063033 分钟前
Windows操作系统部署Tomcat详细讲解
java·windows·tomcat
卓怡学长1 小时前
m280本科生导师指导平台
java·数据库·spring·tomcat·maven·intellij-idea
一直都在5721 小时前
Java死锁
java·开发语言
我真会写代码2 小时前
深度解析并发编程锁升级:从偏向锁到重量级锁,底层原理+面试考点全拆解
java·并发编程·
Meepo_haha2 小时前
创建Spring Initializr项目
java·后端·spring
会编程的土豆2 小时前
C++中的 lower_bound 和 upper_bound:一篇讲清楚
java·数据结构·算法