title: Create X509 certificate and save as Base-64
body: <p>I have been following a guide that covers signing authorization tokens for Web API security. One of the aspects was storing the X509 certificate as a Base-64 string in the web.config. However, the steps necessary on how to get a X509 certificate and convert it into a Base-64 string were not explained. I found some guides on how to generate an X509 certificate using OpenSSL however I remain confused on which parts to use and how to convert to Base-64. Here is what I want to end up with.</p>
  
  <ol>
  <li>A Base-64 representation of the certificate that I can store in the web.config</li>
  <li>A password that goes along with the certificate</li>
  </ol>
  
  <p>The code I want to use in my authentication server is ..</p>
  
  <pre><code>SigningCertificate = new X509Certificate2(certificate, password);
  </code></pre>
  
  <p>Where <code>certificate</code> is a Base 64 encoded representation of the certificate and <code>password</code> is the signing certificate password.</p>
  
  <p>So with the OpenSSL tool I am able to generate two files ...</p>
  
  <ul>
  <li>Cert file - MyCert.pem</li>
  <li>Key file - MyKey.pem</li>
  </ul>
  
  <p><strong>Question #1</strong> - Do I only need to use the <code>MyCert.pem</code> file when converting to Base-64? Or do both files need to combined both files as a single <code>PFX</code> file before representing as Base-64?</p>
  
  <p><strong>Question #2</strong> - Is there a utility that I can use that accepts a file and then exports a Base-64 string?</p>