当前位置:   article > 正文

Springboot - druid 数据库密码加密_springboot druid密码加密

springboot druid密码加密
    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);
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

在这里插入图片描述

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==


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/844091
推荐阅读
相关标签
  

闽ICP备14008679号