title: openssl - RSA public key from PEM to DER
body: <p>I confronted a problem when translating RSA pub key using openssl, I want to get public key in DER format. Here is what I did:</p>
  
  <ol>
  <li><p>generate RSA key pair
  openssl genrsa -out alice.key 1024</p></li>
  <li><p>export only public key from my.key
  a) openssl rsa -in alice.pem -RSAPublicKey_out -out alice_pub.pem
  b) openssl rsa -in alice.pem -pubout -out alice_pub2.pem                </p></li>
  </ol>
  
  <p>The two approaches generate different footers in .pem: the first one outputs 
  <code>--Begin RSA public key ----</code>, and the second outputs 
  <code>-- Begin Public key ----</code></p>
  
  <ol start="3">
  <li><p>When using openssl asn1parse to analyze the two public key pem files, <code>openssl asn1 parse -inform PEM -in alice_pub.pem</code>, something unexpected happened. 
  For alice_pub.pem, it works good; for alice_pub2.pem, openssl is unable to extract the "N" and "E" parameters indicating they have been "rsaEncryption". </p></li>
  <li><p>Openssl can only transform the second pem to DER, however, the pem content is obviously incorrect...</p></li>
  </ol>
  
  <p>pls let me know how to solve this problem. Many thanks.  This issue can be reproduced easily.</p>