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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里