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