Java- RSA加密/解密
RSA rsa = new RSA(AsymmetricAlgorithm.RSA_ECB_PKCS1.getValue(), privateKey, publicKey);
String result = “”;
if(“1”.equals(type)){
//加密
try{
byte[] bytes = rsa.encrypt(req, KeyType.PublicKey);
result = new String(Base64.encodeBase64(bytes));
} catch (Exception e) {
System.out.println(“数据错误,请重新尝试。”);
}
System.out.println(“result=”+result);
}else{
//解析
String decryptByPrivate = “”;
try{
decryptByPrivate = rsa.decryptStr(req, KeyType.PrivateKey);
} catch (Exception e) {
System.out.println(“数据错误,请重新尝试。”);
}
result = decryptByPrivate;
System.out.println(“result=”+result);
}