druid-1.0.16.jar 阿里巴巴的开源数据连接池 jar包
明文密码+私钥(privateKey)加密=加密密码
加密密码+公钥(publicKey)解密=明文密码
程序代码如下:
package com.t1;
import com.alibaba.druid.filter.config.ConfigTools;
public class DruidTest { public static void main(String[] args) throws Exception {
//密码明文
String password = "12345"; System.out.println("密码[ "+password+" ]的加密信息如下:\n"); String [] keyPair = ConfigTools.genKeyPair(512);
//私钥
String privateKey = keyPair[0];
//公钥
String publicKey = keyPair[1];
//用私钥加密后的密文
password = ConfigTools.encrypt(privateKey, password); System.out.println("privateKey:"+privateKey);
System.out.println("publicKey:"+publicKey);
System.out.println("password:"+password);
String decryptPassword=ConfigTools.decrypt(publicKey, password);
System.out.println("decryptPassword:"+decryptPassword); }
}