title: RSA encryption by supplying modulus and exponent
body: <p>I am creating a C# Winforms application which POSTs data to a server over HTTPS.</p>
  
  <p>The login mechanism is supposed to be like this:</p>
  
  <ol>
  <li><p>I send the username to the server, it responds with rsa-modulus and rsa-exponent</p></li>
  <li><p>I encrypt the password using these given parameters and send username + password to the server for authentication</p></li>
  </ol>
  
  <p>I have tried the <code>RSACryptoServiceProvider</code> class, but I cannot find samples or anything said on <strong>how we can do the encryption using a given modulus and exponent?</strong>. </p>
  
  <p>I think that without specifying any values, its doing default encryption parameters..</p>
  
  <p>So if anybody has done this before, can they give me some hints please? thanks</p>
  
  <p><strong>UPDATE</strong>: according to the suggestion by Mr. Carsten Konig, . I have tried to do it with RSAParameters and <code>RSA.ImportParameters</code>, but it returns a "BAD DATA" error with cryptographic exception. My code is given below.</p>
  
  <p>I have also tried <code>RSA.FromXmlString(mykey)</code>; (where <code>mykey</code> contains an xml string with modulus and exp) but I also get a "BAD DATA" errror with cryptographic exception... any idea anybody? or if its some microsoft bug, can anyone suggest some other decent library to do this easily? </p>
  
  <pre><code>RSAParameters rsaparam = new RSAParameters(); 
  rsaparam.Modulus = modbytes; 
  rsaparam.Exponent = expbytes; 
  RSACryptoServiceProvider RSA = new RSACryptoServiceProvider() ; 
  RSA.ImportParameters(rsaparam); 
  byte[] encryptedData = RSA.Encrypt(dataToEncrypt, false)
  </code></pre>