加密过程:
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;
}
然后在解密的时候就出现了,所以这便想请教一下如何解决
http://www.xuebuyuan.com/68875.html 看看这个 或许有用
谢谢,已经找到问题了,是dudu说的那样,在加密完之后用Base64转码一下,在解密之前在Base64反转码一下,这就可以了
对加密完的密文进行Base64转码一下,然后在解密之前再使用Base64反转码一下就可以了