duan6161
duan6161
2013-06-04 18:39
浏览 67

如何解密在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
    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.

    点赞 评论

相关推荐