title: How to extract the RSA public key from a .cer and store it in a .pem using OpenSSL?
body: <p>I have the requirement to extract the public key (RSA) from a <code>*.cer</code> file. I wish to extract the key and store it in a <code>.pem</code> file so I can use its value to encrypt values using <a href="https://github.com/travist/jsencrypt" rel="noreferrer">jsencrypt</a>.</p>
  
  <p>The following command converts a <code>.cer</code> to <code>.pem</code>:</p>
  
  <pre><code>openssl x509 -inform der -in certificate.cer -out certificate.pem
  </code></pre>
  
  <p>Yet it doesn't generate a file with the public key but a file with the contents of the <code>*.cer</code> file.</p>
  
  <pre><code>-----BEGIN CERTIFICATE-----
  MIICPDCCAamgAwIBAg............
  *lots of extra contents*
  -----END CERTIFICATE-----
  </code></pre>
  
  <p><strong>What command should I use to extract the public key and store it in a <code>.pem</code> file?</strong></p>