title: RSA encrypt by PHP and decrypt by C#
body: <p>I'm trying to encryption and decrpytion process between C# and PHP.</p>
  
  <p>My C# code:</p>
  
  <pre><code>this.EncryptData("123456", 1024, this.PublicKey);
  
  public byte[] Encrypt(byte[] byte_0, int keysize, string publicKey)
  {
      byte[] numArray;    
      using (RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider(keysize))
      {
          rSACryptoServiceProvider.FromXmlString(publicKey);
          numArray = rSACryptoServiceProvider.Encrypt(byte_0, this.bool_0);
      }
      return numArray;
  }
  
  public string EncryptData(string string_0, int keysize, string publicKey)
  {
      string base64String;
      try
      {
          byte[] numArray = this.Encrypt(Encoding.UTF8.GetBytes(string_0), keysize, publicKey);
          base64String = Convert.ToBase64String(numArray);
      }
      catch (Exception exception)
      {
          base64String = string.Empty;
      }
      return base64String;
  }
  public byte[] Decrypt(byte[] byte_0, int keysize, string Key)
  {
      byte[] numArray;    
      using (RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider(keysize))
      {
          rSACryptoServiceProvider.FromXmlString(Key);
          numArray = rSACryptoServiceProvider.Decrypt(byte_0, this.bool_0);
      }
      return numArray;
  }
  
  public string DecryptData(string string_0, int keysize, string Key)
  {
      string str;
      try
      {
          byte[] numArray = this.Decrypt(Convert.FromBase64String(string_0), keysize, Key);
          str = Encoding.UTF8.GetString(numArray);
      }
      catch (Exception exception)
      {
          str = string.Empty;
      }
      return str;
  }
  </code></pre>
  
  <p>and my PHP: lib(<a href="https://github.com/membersuite/sdk-php/blob/master/APISample/SSOWithSDK/phpseclib/Crypt/RSA_XML.php" rel="nofollow">https://github.com/membersuite/sdk-php/blob/master/APISample/SSOWithSDK/phpseclib/Crypt/RSA_XML.php</a>)</p>
  
  <pre><code>$rsa = new Crypt_RSA_XML();
  $plaintext = '123456';
  $rsa-&gt;loadKeyfromXML($publicKey);
  $ciphertext = base64_encode(strrev($rsa-&gt;encrypt($plaintext)));
  </code></pre>
  
  <p>code after PHP encrypt cant decrypt by c# code. anyone can help?</p>