public static string RSADecryptByPavKey(string pavKey,string strEncryptString)
{
string clearText = "";
//得到私钥
RsaKeyParameters pavKeyParam = (RsaKeyParameters)PrivateKeyFactory.CreateKey(Convert.FromBase64String(pav));
//参数与Java中加密解密的参数一致
IBufferedCipher c = CipherUtilities.GetCipher("RSA/ECB/PKCS1Padding");
//第一个参数 true-加密,false-解密;第二个参数表示密钥
c.Init(true, pavKeyParam);
//对明文进行UTF8解码
byte[] dataFromEncrypt = Encoding.UTF8.GetBytes(strEncryptString);
//获取循环次数
int count = dataFromEncrypt.Count() / 117;
//获取余数 即为要进行补位的数量
int quyu = dataFromEncrypt.Count() % 117;
//设置分割完的字节数组大小
byte[] _splitarr = new byte[117];
if (quyu == 0)
{
for (int i = 0; i < count; i++)
{
Buffer.BlockCopy(dataFromEncrypt, i * 117, _splitarr, 0, 117);
//加密
byte[] outBytes = c.DoFinal(_splitarr);
//明文
clearText += Convert.ToBase64String(outBytes);
}
}
else
{
int buchong = 117 - quyu;
byte[] buchongarr = new byte[dataFromEncrypt.Count() + buchong];
dataFromEncrypt.CopyTo(buchongarr, 0);
for (int i = 0; i <= count; i++)
{
Buffer.BlockCopy(buchongarr, i * 117, _splitarr, 0, 117);
//加密
byte[] outBytes = c.DoFinal(_splitarr);
//明文
clearText += Convert.ToBase64String(outBytes);
}
}
return clearText;
}