public String doEncrypt(String[] str) throws Exception {
//获取公钥
CertificateFactory cff = CertificateFactory.getInstance("X.509");
String filePath = Log4jInit.getCommString(Consts.jks_path);
InputStream in = new FileInputStream(filePath);// 证书文件
//获得公钥文件(报错的地方)
Certificate cf = cff.generateCertificate(in);
PublicKey pk1 = cf.getPublicKey(); // 得到证书文件携带的公钥
Cipher cipher = Cipher.getInstance("RSA");
// 加密模式
cipher.init(Cipher.ENCRYPT_MODE, pk1);
byte[] msg1 = cipher.doFinal(str.toString().getBytes("UTF-8")); // 加密后的数据
return new BASE64Encoder().encode(msg1);
}
RSA加密算法步骤
最新推荐文章于 2023-01-04 16:19:02 发布