duan6161 2013-06-04 18:39
浏览 71
已采纳

如何解密在C#中使用RSA加密的文本[重复]

This question already has an answer here:

I need to convert code from C# to PHP, with identical results. In C# I finished it pretty quickly, but now need to convert the following code to php:

public static string RsaDecrypt(string privateKey, string src)
{
    CspParameters csp = new CspParameters();
    csp.Flags = CspProviderFlags.UseMachineKeyStore;
    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(csp);
    rsa.FromXmlString(privateKey);
    return RsaDecrypt(rsa, src);
}

public static string RsaDecrypt(RSACryptoServiceProvider rsa, string src)
{
    byte[] srcData = Convert.FromBase64String(src);
    byte[] destData = rsa.Decrypt(srcData, false);
    return Encoding.UTF8.GetString(destData);
}

I'm trying to hours and I can not, I'm using the phpseclib0.2.1a file and the code:

Pastebin

The Problem in PHP is returning the following error:

Notice: Decryption error in E:\AppServWWW\Request\Flash\Crypt\RSA.php on line 1582

@EDIT: My $_GET["p"] is

cwQPQLSW%2FQ70AUmBzkZ9c7d9MrEAcPAAN1lRG937XZuibDOE304i8894uowlC1OANnWEim6suOxzhEHZl0BR1G1audk4CWG1TUSqAo4MO5FBfVbmcLVMx1KPV9%2FeMzil%2BHM1XwyX3Dm0h%2F0uAxORfpa3waq0iOemkUYBq2lXDEU%3D

</div>
  • 写回答

1条回答 默认 最新

  • drj14664 2013-06-04 21:26
    关注

    The latest version of phpseclib is 0.3.1 so, first, I'd recommend you upgrade.

    Second... phpseclib does OAEP padding by default. C# is probably doing PKCS1 padding by default. So you'd need to do $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1); before doing the actual decryption in PHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多尺度特征图提取和融合
  • ¥15 微信小程序:渲染收货地址时页面不显示
  • ¥20 win7 64位DirectShow提示初始化失败如何解决?
  • ¥20 小规模孤立词识别系统设计
  • ¥15 关于Java对接海康威视车牌识别一体机SDK是否需要固定外网的IP?
  • ¥15 Linux扩容时,格式化卡住了:vgdispaly查看卷组信息,没有输出
  • ¥18 关于#ubuntu#的问题:使用背景-工作职责内有七八台ubuntu系统的电脑,平时需要互相调取资料,想实现把这几台电脑用交换机组成一个局域网,来实现指定文件夹的互相调取和写入
  • ¥20 求一个简易射频信号综测仪
  • ¥15 esp8266 tally灯 接收端改为发射端
  • ¥30 Labview代码调用access 数据库,相同代码其中一个调用不出来是为什么