title: C# Import private key to X509Certificate2
body: <p>In C#, I need to load a <code>X509Certificate2</code> with an encrypted private key, imported from a .key file. The <code>RSACryptoServiceProvider</code> does not take any arguments to import such key, and my research has not provided any success.</p>
  
  <p>I have tried <a href="https://www.codeproject.com/Articles/162194/Certificates-to-DB-and-Back" rel="nofollow noreferrer">this link</a>.</p>
  
  <p>The certificate is used to retrieve JSON from a REST API.</p>