Tom
Tom

Reputation: 95

How to load a private key from a byte array in Apache MINA SSHD 2.11.0?

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:

  1. How can I load a private key from a byte array in Apache MINA SSHD 2.11.0 for authentication?
  2. 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!

Upvotes: 0

Views: 54

Answers (1)

Related Questions