2013-06-04 18:39
浏览 67


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);
    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:


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


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    点赞 评论