Sure, but that's definitely now how the private key looks like. It usually looks like:
-----BEGIN RSA PRIVATE KEY----- .... -----END RSA PRIVATE KEY----- And loading the public key only won't really give you a KeyPair. The method I pointed you to in SecurityUtils needs an InputStream containing such a private key. Guillaume 2015-11-02 17:25 GMT+01:00 Jonathan S. Fisher < [email protected]>: > Jsch loads encrypted ones just fine :) It will not connect with ECDSA > though, which is why we switched to mina-sshd. > > And those are definitely PEM encoded keys. Typically with the ssh-keygen > tool, your generated pubkey will be in this format: > > jonathan.fisher@apollo:~/.ssh$ cat id_dsa.pub > ssh-dss > > AAAAB3NzaC1kc3MAAACBANgv/c/e+Urs13PJiwCAeGZshnmv4eea8+c8NEPS5fYi9WHSdSGacyZJPxqd1/8dlmzma91lx2i20f1jTUngiXal2OUzADxIiUf+nf0LFRSrzPbo6B6bLcaYz0RHoSzICbcImreJ06Cow9nKGM0zCwho3aRrPo41L9hDzDFjYPKJAAAAFQC4ybSPtFEb2GuIqTpz3HRAlOU0kwAAAIEArBxXFV+CgEh57uPSsQ/G2p2KhEXyOTP8SZ753sRswH5PTv8X3wq1BjuSneonm9Z+1w6AtC0HDQ6ibTG+Kx0e3HjAdVdkvVEP2MNLxlYG5eUozGJWEdb3tmAGJgtP4Y3pQ789I1fbaEtN7JT7+tn9IXtclGP66du6XhU3lHemqVMAAACAFVAaT56J7KnM2FGD4ghQ5+dduM3mzRrokac7oEt9gz18n0yK5bBRMUq4evEwsRyqEH8lipdvF416ggK/I5U5ww2XwsfqqJ8mAPuGpC49cIQzuCWDi1WMG0OA91t/bTD4yEt0DA/7Vqo+PVFbxzVbAZtoGMa/0trjvIgxRJfLOss= > jonathan.fisher@apollo > > > On Mon, Nov 2, 2015 at 10:20 AM, Guillaume Nodet <[email protected]> > wrote: > > > The code is used to load the following keys: > > > > > > > https://github.com/apache/mina-sshd/tree/master/sshd-core/src/test/resources/org/apache/sshd/client/config/keys > > > > Isn't that what you need ? > > > > Fwiw, afaik, JSch can't load encrypted keys. > > > > > > 2015-11-02 17:00 GMT+01:00 Jonathan S. Fisher < > > [email protected]>: > > > > > If I could press you just a bit further.... > > > > > > I have the private key and the public key as separate strings in the > > > typical OpenSSH format. I noticed the source code for the > > > SecurityUtils. loadKeyPairIdentity() seems to invoke methods based > around > > > PEM formats, which is not common at all for SSH. > > > > > > Is there a way to parse, combine, and convert the keys I have to PEM > > format > > > in Java? > > > > > > On Mon, Nov 2, 2015 at 9:44 AM, Jonathan S. Fisher < > > > [email protected]> wrote: > > > > > > > https://mina.apache.org/sshd-project/downloads.html > > > > > > > > Just noticed this is not showing a changelog or a download link for > > 1.0. > > > I > > > > saw v1.0 in Nexus, but since it wasn't listed as a release I figured > it > > > was > > > > a fluke. > > > > > > > > On Sun, Nov 1, 2015 at 2:50 AM, Guillaume Nodet <[email protected]> > > > wrote: > > > > > > > >> Here's the code from SSHD 1.0 > > > >> I think the javadoc on the web site is outdated, i'll try to fix it. > > > >> > > > >> > > > >> > > > > > > https://github.com/apache/mina-sshd/blob/sshd-1.0.0/sshd-core/src/main/java/org/apache/sshd/common/util/SecurityUtils.java#L202 > > > >> > > > >> 2015-10-31 16:24 GMT+01:00 Jonathan S. Fisher < > > > >> [email protected]>: > > > >> > > > >> > Using Jsch, I was able to parse the keys: > > > >> > > > > >> > JSch jSch = new JSch(); > > > >> > try { > > > >> > com.jcraft.jsch.KeyPair jschKeypair = > > > com.jcraft.jsch.KeyPair.load(jSch, > > > >> > privateKey.getBytes(), publicKey.getBytes()); > > > >> > jschKeypair.decrypt(keyPass); > > > >> > byte[] fromAgent = jschKeypair.forSSHAgent(); > > > >> > Buffer buffer = new Buffer(fromAgent); > > > >> > return buffer.getKeyPair(); > > > >> > } catch (JSchException | SshException e) { > > > >> > throw new RuntimeException(e); > > > >> > } > > > >> > > > > >> > However, is there a way to do this without bringing in Jsch? > > > >> > > > > >> > > > > >> > On Sat, Oct 31, 2015 at 9:12 AM, Jonathan S. Fisher < > > > >> > [email protected]> wrote: > > > >> > > > > >> > > > > > >> > > > > > >> > > > > >> > > > > > > https://mina.apache.org/sshd-project/apidocs/org/apache/sshd/common/util/SecurityUtils.html > > > >> > > > > > >> > > Can you point me to that method in the docs? I'm not seeing it > > > >> there... > > > >> > > > > > >> > > On Fri, Oct 30, 2015 at 5:59 PM, Guillaume Nodet < > > [email protected] > > > > > > > >> > > wrote: > > > >> > > > > > >> > >> You can try with > > > >> > >> SecurityUtils.loadKeyPairIdentity > > > >> > >> > > > >> > >> 2015-10-30 17:36 GMT+01:00 Jonathan S. Fisher < > > > >> > >> [email protected]>: > > > >> > >> > > > >> > >> > Hey guys, > > > >> > >> > > > > >> > >> > I've been pouring through examples and source code, and I > > cannot > > > >> > figure > > > >> > >> out > > > >> > >> > how to do this. I have a pair of Strings that is the contents > > of > > > a > > > >> > >> user's > > > >> > >> > id_ecdsa and id_ecdsa.pub. The private key is encrypted. > > > >> > >> > > > > >> > >> > Is there not a conversion utility class to go from OpenSSH > to a > > > >> > KeyPair > > > >> > >> > anywhere? If not, what would be the shortest steps to write > > one? > > > I > > > >> > >> noticed > > > >> > >> > the Buffer class and the SecurityUtils, but they don't seem > to > > > >> handle > > > >> > >> > encryption. > > > >> > >> > > > > >> > >> > Thanks, > > > >> > >> > -Jonathan > > > >> > >> > > > > >> > >> > -- > > > >> > >> > Email Confidentiality Notice: The information contained in > this > > > >> > >> > transmission is confidential, proprietary or privileged and > may > > > be > > > >> > >> subject > > > >> > >> > to protection under the law, including the Health Insurance > > > >> > Portability > > > >> > >> and > > > >> > >> > Accountability Act (HIPAA). The message is intended for the > > sole > > > >> use > > > >> > of > > > >> > >> the > > > >> > >> > individual or entity to whom it is addressed. If you are not > > the > > > >> > >> intended > > > >> > >> > recipient, you are notified that any use, distribution or > > copying > > > >> of > > > >> > the > > > >> > >> > message is strictly prohibited and may subject you to > criminal > > or > > > >> > civil > > > >> > >> > penalties. If you received this transmission in error, please > > > >> contact > > > >> > >> the > > > >> > >> > sender immediately by replying to this email and delete the > > > >> material > > > >> > >> from > > > >> > >> > any computer. > > > >> > >> > > > > >> > >> > > > >> > > > > > >> > > > > > >> > > > > >> > -- > > > >> > Email Confidentiality Notice: The information contained in this > > > >> > transmission is confidential, proprietary or privileged and may be > > > >> subject > > > >> > to protection under the law, including the Health Insurance > > > Portability > > > >> and > > > >> > Accountability Act (HIPAA). The message is intended for the sole > use > > > of > > > >> the > > > >> > individual or entity to whom it is addressed. If you are not the > > > >> intended > > > >> > recipient, you are notified that any use, distribution or copying > of > > > the > > > >> > message is strictly prohibited and may subject you to criminal or > > > civil > > > >> > penalties. If you received this transmission in error, please > > contact > > > >> the > > > >> > sender immediately by replying to this email and delete the > material > > > >> from > > > >> > any computer. > > > >> > > > > >> > > > > > > > > > > > > > > -- > > > Email Confidentiality Notice: The information contained in this > > > transmission is confidential, proprietary or privileged and may be > > subject > > > to protection under the law, including the Health Insurance Portability > > and > > > Accountability Act (HIPAA). The message is intended for the sole use of > > the > > > individual or entity to whom it is addressed. If you are not the > intended > > > recipient, you are notified that any use, distribution or copying of > the > > > message is strictly prohibited and may subject you to criminal or civil > > > penalties. If you received this transmission in error, please contact > the > > > sender immediately by replying to this email and delete the material > from > > > any computer. > > > > > > > -- > Email Confidentiality Notice: The information contained in this > transmission is confidential, proprietary or privileged and may be subject > to protection under the law, including the Health Insurance Portability and > Accountability Act (HIPAA). The message is intended for the sole use of the > individual or entity to whom it is addressed. If you are not the intended > recipient, you are notified that any use, distribution or copying of the > message is strictly prohibited and may subject you to criminal or civil > penalties. If you received this transmission in error, please contact the > sender immediately by replying to this email and delete the material from > any computer. >
