title: How to set public key in RSAParameters
body: <p>I have RSA public key encoded in Base64.
  After decoding I can get RSA public key like:</p>
  
  <blockquote>
    <p>-----BEGIN PUBLIC KEY----- XXXXXXXXXXXXXXXXXXXXXXX
    -----END PUBLIC KEY-----</p>
  </blockquote>
  
  <p>Now I need to import this key into RSACryptoServiceProvider.
  I was looking for solution but wasn't able to find anything working.
  From pieces I found, I created such code sample</p>
  
  <pre><code>    public static string Encrypt(string input, string base64PublicKey)
      {
          var rsa = new RSACryptoServiceProvider();
          var byteKey = System.Convert.FromBase64String(base64PublicKey);
          var byteInput = Encoding.UTF8.GetBytes(input);
  
          var parameters = rsa.ExportParameters(false);
          parameters.Modulus = byteKey;
  
          rsa.ImportParameters(parameters);
  
          var bytesEncrypted = rsa.Encrypt(byteInput, false);
  
          var result = System.Convert.ToBase64String(bytesEncrypted);
  
          return result;
      }
  </code></pre>
  
  <p>I suppose it is not working correctly, because I always get response with error from the system I'm integrating with.</p>
  
  <p>Is it a correct way to import public key?
  If not how should I do it?</p>