本文介绍了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
类具有方法-
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从字符串添加私钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!