title: How to create a valid, self-signed X509Certificate2 programmatically, not loading from file in .NET Core
body: <p>What I currently do is that I use OpenSSL to generate PFX file. This is causing an unwanted dependency, especially for Windows users. So I found some examples on how to create your own certificate using BouncyCastle, but this library is not .NET Core compatible (or I failed to find the compatible package).</p>
  
  <p>So, is it possible to create your own self signed X509 certificate using just .NET core to avoid dependency on OpenSSL (or any other certificate generating external tool)?</p>
  
  <p><strong>EDIT:</strong> It was suggested by someone (editor?) that this SO question <a href="https://stackoverflow.com/questions/13806299/how-to-create-a-self-signed-certificate-using-c">How to create a self-signed certificate using C#?</a> provides an answer. Sadly again, this has nothing to do with .NET Core. The accepted answer there starts with <code>This implementation uses the CX509CertificateRequestCertificate COM object (and friends - MSDN doc) from certenroll.dll to create a self signed certificate request and sign it</code>, which is obviously NOT .NET Core ... In fact, none of the answers there is .NET Core compatible.</p>