最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - How to load a private key from a byte array in Apache MINA SSHD 2.11.0? - Stack Overflow

programmeradmin1浏览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!

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!

Share Improve this question asked Feb 15 at 9:15 TomTom 956 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Use 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)

发布评论

评论列表(0)

  1. 暂无评论