title: How to convert OpenSSH private key to RSA private key in Java?
body: <p>I have a private key file in OpenSSH format:</p>
  
  <pre><code>-----BEGIN OPENSSH PRIVATE KEY-----
  ...
  -----END OPENSSH PRIVATE KEY-----
  </code></pre>
  
  <p>but I need it in RSA format:</p>
  
  <pre><code>-----BEGIN RSA PRIVATE KEY-----
  ...
  -----END RSA PRIVATE KEY-----
  </code></pre>
  
  <p>On the terminal I would do this:</p>
  
  <pre><code>ssh-keygen -p -m PEM -f my-openssh-file
  </code></pre>
  
  <p>but I need to do it in Java.</p>
  
  <p>I've tried using org.bouncycastle.openssl.PEMWriter, but I can't work out how to convert my input key (as an input string) to a PrivateKey object that can be passed to the PEMWriter.</p>