title: How to get public key in .cer or .crt formats
body: <p>I have created self-signed SSL certificate using OpenSSL as follow:</p>
  
  <pre><code>openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365
  </code></pre>
  
  <p>This gave me certificate and private key in <code>.pem</code> file. I need to provide my public key to my clients in <code>.cer</code> or <code>.crt</code> format. <strong>Is there any way to get public key in <code>.cer</code>/<code>.crt</code> formats?</strong></p>
  
  <p>What I have already tried:</p>
  
  <p><strong>1. Generating public key in <code>.pem</code> format and trying to convert it to <code>.cer</code> or <code>.crt</code> [<em>Didn't work</em>]</strong></p>
  
  <p>To extract public key in <code>.pem</code> file [worked fine]:</p>
  
  <pre><code>`openssl x509 -pubkey -noout -in signer-cert.pem  &gt; signer-public-key-test.pem`
  </code></pre>
  
  <p>To convert it from <code>.pem</code> for <code>.cer</code> format
  <code>openssl x509 -inform PEM -in signer-public-key-test.pem -outform DER -out signer-public-key-test.cer</code>
  I get this error:</p>
  
  <pre><code>unable to load certificate
  140067363030680:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:701:Expecting: TRUSTED CERTIFICATE
  </code></pre>
  
  <p><strong>2. Converting my certificate to .cer (which I did fine) and trying to export public key using windows certificate export wizard as instructions given <a href="https://support.globalsign.com/customer/portal/articles/1295563-step-4-export-public-key---fda-esg" rel="nofollow noreferrer">here</a></strong></p>
  
  <p>It didn't work either. I couldn't enable the option to export keys and the final output, when opened in notepad++ was garbage.</p>
  
  <p>So my question is, is there any way to generate the certificate from scratch and have the public key in <code>.cer</code> or <code>.crt</code> file. OR generating the certificate in <code>.pem</code> format and later extracting public keys to <code>.crt</code> or <code>.cer</code></p>
  
  <p>Any help is deeply appreciated.</p>