mysql数据库-链接密码加密

# 此种方式可以,隐藏明文密码,druid方案
# 参考资料:
## https://blog.csdn.net/m0_46360888/article/details/128369783
## https://blog.csdn.net/xiha_zhu/article/details/126423798


## 注意事项
#### 1、要配置 spring.datasource.druid 以下的连接属性 和 开启 过滤器配置为true
#### 2、 连接的url后面填充 &allowPublicKeyRetrieval=true 否则会报: Public Key Retrieval is not allowed

spring:
  datasource:

    driverClassName: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/user_center?tinyInt1isBit=false&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
    username: root
    password: LYC+aEgv/rTstxmP/OPIb9ZG0IY2aQQ6t3yWQMrSHm9SxJzVkGCvVULrSHRRnCjB2jtvLTeNhjmhrNzX87NggQ==
    publickey: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJfkYlPQdxKu1ghc4UulZDiUSF/2zjCcEISJpdYlrD7/d20JOjtNfkYnXmvtJ1GFmFtwV163HjhtjMVNC/S3DocCAwEAAQ==
    druid:
      connection-properties: config.decrypt=true;config.decrypt.key=${spring.datasource.publickey}
      filter:
        config:
          enabled: true

方案一:

/**
 * 方案1
 */
//需要加密的明文密码
String password = "root1234";
// 调用 druid 工具类 生成私钥、公钥、密文
ConfigTools.main(new String[]{password});

方案二;
#-- 进入到 com/alibaba/druid 文件夹下面,
#cd /Users/admin/Desktop/work_common/apache-maven/repository/com/alibaba/druid/1.0.18

#-- 对明文密码进行 生成公钥、私钥 以及密码的密文 :scotttiger 是密码
#java -cp druid-1.0.18.jar com.alibaba.druid.filter.config.ConfigTools root1234

#privateKey:MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAl+RiU9B3Eq7WCFzhS6VkOJRIX/bOMJwQhIml1iWsPv93bQk6O01+Ridea+0nUYWYW3BXXrceOG2MxU0L9LcOhwIDAQABAkEAhLOyuDk0Hq2DLxE+gGGCGvBp/vVYlR10TOcZbOvC/dHCYNb4j8BiJ15TT4+6BNF7BjWq9jkxtdn4hp0K6Jp2OQIhAPDe58Cy8j/RQdP/axNRJP1jiRcX02lV1QMcCj6cUeedAiEAoW6+BwVXR09540O2wzqrPv7SSjm8IimOv7a6z+5gH3MCIQCZSKEfJkG3jwlfSgnwDxGFFxSk14q4W+Dky7FRStVsmQIgCP0ChZ+NgYHyVm4RwgMFP+euS8W1LO3FbfU9p5AtN/MCIEkrXuqS/Rpl1TUK0VdPqkQxHfbEdcAnvENpI4nvEzRW
#publicKey:MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJfkYlPQdxKu1ghc4UulZDiUSF/2zjCcEISJpdYlrD7/d20JOjtNfkYnXmvtJ1GFmFtwV163HjhtjMVNC/S3DocCAwEAAQ==
#password:LYC+aEgv/rTstxmP/OPIb9ZG0IY2aQQ6t3yWQMrSHm9SxJzVkGCvVULrSHRRnCjB2jtvLTeNhjmhrNzX87NggQ==

你可能感兴趣的:(数据库,mysql)