title: Keytool - Generate Public key in X.509 format using existing private key
body: <p>I am trying to generate a private/public key pair in <code>X.509</code> format along with a self signed cert which I need to use for my SAML application.</p>
  
  <p>Here is what I have done:</p>
  
  <ol>
  <li>Generate Self Signed Cert and Private Key from <a href="https://www.samltool.com/self_signed_certs.php" rel="nofollow noreferrer">here</a> and save
  them in <code>.pem</code> format.</li>
  <li>Use the private key and generate a public key
  with the command <code>openssl rsa -in key.pem -pubout -out pubkey.pem</code></li>
  </ol>
  
  <p>When I give these keys to my SAML application, it errors out on the public key generated on step 2 with the following message:</p>
  
  <p><code>java.io.IOException: Short read of DER length</code></p>
  
  <p>What's that I am doing wrong here? </p>