I am migrating an SFTP client from JSch to Apache MINA SSHD (version 2.11.0) and need to authenticate using a private key stored as a byte array.
With JSch, I used the following approach to authenticate:
JSch jsch = new JSch();
jsch.addIdentity("sftp-key", privateKeyBytes, null, passphrase.getBytes());
Session jschSession = jsch.getSession(username, host, port);
Properties properties = new Properties();
properties.put("StrictHostKeyChecking", "no");
jschSession.setConfig(properties);
jschSession.connect();
Channel channel = jschSession.openChannel("sftp");
In Apache MINA SSHD, I couldn't find a straightforward way to load the private key directly from a byte array. Most examples seem to work with keys stored as files
What I Need Help With:
- How can I load a private key from a byte array in Apache MINA SSHD 2.11.0 for authentication?
- Is there an alternative way to achieve this without writing the key to a temporary file?
Any guidance or code examples would be greatly appreciated!
I am migrating an SFTP client from JSch to Apache MINA SSHD (version 2.11.0) and need to authenticate using a private key stored as a byte array.
With JSch, I used the following approach to authenticate:
JSch jsch = new JSch();
jsch.addIdentity("sftp-key", privateKeyBytes, null, passphrase.getBytes());
Session jschSession = jsch.getSession(username, host, port);
Properties properties = new Properties();
properties.put("StrictHostKeyChecking", "no");
jschSession.setConfig(properties);
jschSession.connect();
Channel channel = jschSession.openChannel("sftp");
In Apache MINA SSHD, I couldn't find a straightforward way to load the private key directly from a byte array. Most examples seem to work with keys stored as files
What I Need Help With:
- How can I load a private key from a byte array in Apache MINA SSHD 2.11.0 for authentication?
- Is there an alternative way to achieve this without writing the key to a temporary file?
Any guidance or code examples would be greatly appreciated!
Share Improve this question asked Feb 15 at 9:15 TomTom 956 bronze badges1 Answer
Reset to default 0Use SecurityUtils.loadKeyPairIdentities
to read a KeyPair
from any InputStream
.
https://javadoc.io/doc/.apache.sshd/sshd-common/latest//apache/sshd/common/util/security/SecurityUtils.html#loadKeyPairIdentities(.apache.sshdmon.session.SessionContext,.apache.sshdmon.NamedResource,java.io.InputStream,.apache.sshdmon.config.keys.FilePasswordProvider)