首页 新闻 会员 周边 捐助

C#rsa解密的解出来的结果乱码

0
悬赏园豆:40 [已解决问题] 解决于 2017-04-11 17:28

关于C#rsa解密的问题,代码里面引用了BouncyCastle.CS文件,但是解出来的结果乱码

static void Main(string[] args)
{

var rsaHelper = new RsaHelper();
var test1 =
"i0s9lv0QuefmmXWkWxqIwJMcK1/uOjTTIpc0K2YWAwFGuMSbQ651Zfl4i7MY/Qi/vG8+J7SRyb3UWiS5CNP3M3MI2tC6l2CVAGv0godSMaeWbMqj9g17KwJr9r3EYtPvc8lRi8ec3qS8plkoPUCoz3PtsK LZ9hBlAXKD3f8qGDI=";
var key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxtkuwBI6novN6IKoP3AUe7vQnT +3NqYy0SJqGTf4u5sWuKj6jwpvBSf17DoBGAXPVfzQjtl3xNymn/87c7qzDzollBH1dXAdg5olwp0tAUVEWDKuCgaFGjsqnrTYxTvOqTf1J08mIQf3Tngkw1WuNBdADUiBsTlgpO9k+ffIL4wIDAQAB";
var source = rsaHelper.DecryptByPublibKey(test1, key);
Console.WriteLine("通过公钥解密后的原文是:{0}", source);

Console.ReadKey();

}


/// <summary>
/// 公钥解密(key公钥解密)- 必须对应私钥加密
/// </summary>
/// <param name="source">加密后的数据(密文)</param>
/// <param name="publicKey">公钥</param>
/// <returns></returns>
public string DecryptByPublibKey(string source, string publicKey)
{
var publicInfoByte = Convert.FromBase64String(publicKey);
Asn1Object pubKeyObj = Asn1Object.FromByteArray(publicInfoByte);//这里也可以从流中读取,从本地导入
AsymmetricKeyParameter pubKey = PublicKeyFactory.CreateKey(SubjectPublicKeyInfo.GetInstance(pubKeyObj));
//开始解密
IAsymmetricBlockCipher cipher = new RsaEngine();
cipher.Init(false, pubKey);
//解密已加密的数据
byte[] encryptedData = Convert.FromBase64String(source);
encryptedData = cipher.ProcessBlock(encryptedData, 0, encryptedData.Length);
return Encoding.UTF8.GetString(encryptedData, 0, encryptedData.Length);
}

 
高卿的主页 高卿 | 初学一级 | 园豆:8
提问于:2016-01-19 11:47
< >
分享
最佳答案
-3

哈哈~都解决了....

收获园豆:40
幻天芒 | 高人七级 |园豆:37207 | 2016-01-19 20:51
其他回答(1)
0

 您好,请问是怎么解决的

哈库拉灬玛塔塔 | 园豆:202 (菜鸟二级) | 2018-04-03 12:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册