You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.0 KiB

package com.eco.plugin.xx.kksso.utils;
import javax.crypto.Cipher;
import java.security.KeyFactory;
import java.security.interfaces.RSAPrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;
public class RSAUtil {
/**
* RSA私钥解密
*
* @param str 加密字符串
* @param privateKeyString 私钥
* @return 明文
* @throws Exception 解密过程中的异常信息
*/
public static String decrypt(String str, String privateKeyString) throws Exception{
//64位解码加密后的字符串
byte[] inputByte = EncryptUtils.base64DecodeB(str);
//base64编码的私钥
byte[] decoded = EncryptUtils.base64DecodeB(privateKeyString);
RSAPrivateKey priKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded));
//RSA解密
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, priKey);
String outStr = new String(cipher.doFinal(inputByte));
return outStr;
}
}