title: Load ASN.1/DER encoded RSA keypair in C#
body: <p>I have DER encoded RSA keypair created in Crypto++, as well as cipher. They are Base64Encoded string. I first decode the data from Base64 to byte array, but I am not sure how to load them into <code>RSACryptoServiceProvider</code>.</p>
  
  <pre class="lang-cs prettyprint-override"><code>static void Main()
  {
      string pbkeystr = "mypublickey";
      string pvkeystr = "myprivatekey";
      string cipherstr = "mycipher";
  
      byte[] pbkey = Convert.FromBase64String(pbkeystr);
      byte[] pvkey = Convert.FromBase64String(pvkeystr);
      byte[] cipher = Convert.FromBase64String(cipherstr);
  
      RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
  
      //Set keys here..
  
      //Decrypt the cipher using private key
      rsa.Decrypt(pvkey, false);
  }
  </code></pre>
  
  <p>There are no functions to set keys. The only thing I found was <code>ImportParameters</code> method, which takes <code>RSAParameters</code> class which consists of <code>p</code>, <code>q</code>, <code>n</code>, modulus, exponent etc. I don't have access to these.</p>
  
  <p>Is there any way I can load the keys as string? How can I load the key into <code>RSACryptoServiceProvider</code>?</p>