JSch 从字符串中添加私钥 [英] JSch to add private key from a string

查看:31
本文介绍了JSch 从字符串中添加私钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 SFTP 密钥对文件的内容作为字符串.我需要使用 JSch 添加内容,但 addIdentity 只接受文件路径.无论如何我可以做到这一点吗?

I have the contents of the key pair file for SFTP as a string. I need to use JSch to add the contents, but addIdentity only accepts a file path. Is there anyway I can do this?

我看到 KeyPair 类有一个方法 -

I see that the KeyPair class has a method -

KeyPair load(JSch jsch, byte[] bytes, byte[] bytes1)

我不确定这是做什么的.

I'm not sure what this does.

推荐答案

有一个 addIdentity 从缓冲区获取密钥的重载:

There is an addIdentity overload that takes the key from a buffer:

public class JSch {
    ...
    public void addIdentity(String name, byte[]prvkey, byte[]pubkey, byte[] passphrase)

<小时>

另请参见将私钥作为字符串的 Java SFTP 客户端.

有关实现示例,请参阅JSch:来自存储在 hdfs 上的私钥的 addIdentity.

For an example of implementation, see JSch: addIdentity from private key stored on hdfs.

另请参阅在 Android 应用中的 Java JSch 中从字符串或资源加载私钥,了解缓冲区.

See also Loading private key from string or resource in Java JSch in Android app for a format of the key in the buffers.

这篇关于JSch 从字符串中添加私钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆