title: .net To Mono -> System.Security.Cryptography.CryptographicException: Private/public key mismatch
body: <pre><code>Unhandled Exception: System.Security.Cryptography.CryptographicException: Private/public key mismatch
    at Mono.Security.Cryptography.RSAManaged.ImportParameters (RSAParameters parameters) [0x00000] in &lt;filename unknown&gt;:0 
    at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters (RSAParameters parameters) [0x00000] in &lt;filename unknown&gt;:0 
    at BlaBlaFunc() [0x00000] in &lt;filename unknown&gt;:0 
  [ERROR] FATAL UNHANDLED EXCEPTION: System.Security.Cryptography.CryptographicException: Private/public key mismatch
    at Mono.Security.Cryptography.RSAManaged.ImportParameters (RSAParameters parameters) [0x00000] in &lt;filename unknown&gt;:0 
    at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters (RSAParameters parameters) [0x00000] in &lt;filename unknown&gt;:0 
    at BlaBlaFunc() [0x00000] in &lt;filename unknown&gt;:0 
  </code></pre>
  
  <p>Here is the Source Code:</p>
  
  <pre><code>    string foo = "blabla";
  
      System.Security.Cryptography.RSAParameters rsa_params = new System.Security.Cryptography.RSAParameters();
  
      rsa_params.Modulus = Enumerable.Range(0, pubkey.Length)
                           .Where(x =&gt; x % 2 == 0)
                           .Select(x =&gt; System.Convert.ToByte(pubkey.Substring(x, 2), 16))
                           .ToArray();
      rsa_params.Exponent = new byte[] { 1, 0, 1 };
      System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider();
      System.Security.Cryptography.RSAParameters d = rsa.ExportParameters(false);
      rsa.ImportParameters(rsa_params);
  
      byte[] sp = rsa.Encrypt(Encoding.UTF8.GetBytes(foo), false);
  </code></pre>
  
  <p>The .exe file which works fine in windows is compiled with vs2010. It was runned with mono under Ubuntu.</p>
  
  <p>Run with this command:</p>
  
  <pre><code>  mono --runtime=v4.0.30319 xxx.exe
  </code></pre>
  
  <p>How can i fix this?</p>