在C#中使用RSACryptoServiceProvider时,出现下面的错误:
The data to be decrypted exceeds the maximum for this modulus of 128 bytes
私钥在mac下用openssl命令生成的:
openssl genrsa -out rsa_1024_priv.pem 1024
对密文进行base64解码后,问题解决。
System.Convert.FromBase64String(cipherText);
你好!请问这个是指生成的秘钥吗
@Sir Chen: 不是秘钥,是加密后的文本
@dudu: 在解密的时候是否要想法的操作
@dudu:
加密过程:
private byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding)
{
byte[] encryptedData;
//Create a new instance of RSACryptoServiceProvider.
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
//Import the RSA Key information. This only needs
//toinclude the public key information.
RSA.ImportParameters(RSAKeyInfo);
//Encrypt the passed byte array and specify OAEP padding.
//OAEP padding is only available on Microsoft Windows XP or
//later.
encryptedData = RSA.Encrypt(DataToEncrypt, DoOAEPPadding);
}
return encryptedData;
}
解密过程:
/// <summary>
///
/// 私钥解密
/// </summary>
/// <param name="DataToDecrypt"></param>
/// <param name="RSAKeyInfo"></param>
/// <param name="DoOAEPPadding"></param>
/// <returns></returns>
private byte[] RSADecrypt(byte[] DataToDecrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding)
{
byte[] decryptedData;
//Create a new instance of RSACryptoServiceProvider.
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
//Import the RSA Key information. This needs
//to include the private key information.
RSA.ImportParameters(RSAKeyInfo);
//Decrypt the passed byte array and specify OAEP padding.
//OAEP padding is only available on Microsoft Windows XP or
//later.
decryptedData = RSA.Decrypt(DataToDecrypt, DoOAEPPadding);
}
return decryptedData;
}
然后在解密的时候就出现了,所以这便想请教一下如何解决
有qq吗?可以详细问一下吗
建议在博问中提问