JSch 从字符串中添加私钥 [英] JSch to add private key from a string
问题描述
我有 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.
推荐答案
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)
<小时>
有关实现示例,请参阅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屋!