title: Convert a X509 Public key to RSA public key
body: <p>I have a public key in the following format</p>
  
  <p><code>
  -----BEGIN PUBLIC KEY-----
  xxxxxxxx
  -----END PUBLIC KEY-----
  </code></p>
  
  <p>I need to convert this into the following format</p>
  
  <p><code>
  -----BEGIN RSA PUBLIC KEY-----
  xxxxxxxxx
  -----END RSA PUBLIC KEY-----
  </code></p>
  
  <p>Basically, the issue is that I am working with a third party library which is written in Java.</p>
  
  <ol>
  <li><p>The third party library uses Java class "RSAPublicKeySpec" to generate an instance of type RSAPublicKey from a String. </p></li>
  <li><p>The String that I am supplying to this third party library is taken from a file which is in the following format:</p></li>
  </ol>
  
  <p><code>
  -----BEGIN PUBLIC KEY-----
  xxxxxxxx
  -----END PUBLIC KEY-----
  </code></p>
  
  <ol start="3">
  <li>After poking around with the code a bit, I could see that if I use the java class "X509EncodedKeySpec" to load this public key, the signature verification portion of my code works perfectly. However, since the code is a third-party library, I don't have an option of changing the class type in their code. I would need to somehow make sure that the input I am supplying to the library is compatible with "RSAPublicKeySpec" class so that the public key is loaded correctly.</li>
  </ol>