c# - JSch 和 sharpSSH 的主要文件格式是什么?

标签 c# java sftp jsch sharpssh

我正在考虑使用 JSch 库(或者实际上是它的 sharpSSH C# 端口)为 SFTP 设置公钥客户端和服务器身份验证。不幸的是,我找不到任何关于关键加载函数使用的文件格式的文档:

jsch.addIdentity(filename, passphrase);
jsch.setKnownHosts(filename);

私钥和已知主机文件使用什么文件格式?

最佳答案

JSch 使用 OpenSSH key 文件 格式(用于公钥和私钥)。我没有找到这种格式的规范,但你可以使用 OpenSSH 的 ssh-keygen将 key 从/转换为其他格式的工具(谷歌将展示其他从/转换为更多格式的工具)。

更新:在询问 OpenSSH 邮件列表并阅读一些 RFC 之后,OpenSSH 的公钥文件似乎包含(对于版本 2 key )RFC 4253 (section 6.6) 中指定的公钥。 ,只是用 base64 环绕它(键类型作为前缀,注释字段作为后缀)。我仍然没有找到私钥文件的规范。

不幸的是,JSch 的官方文档几乎不存在,但我确实写了一些 Javadocs为了它。 (虽然似乎没有提到 key 文件格式......我必须解决这个问题。) 还有 Manual在 JSch Wiki 中,包含一个关于 public key authentication 的页面(也没有提到 key 格式 :-/)。

已知主机文件的格式也与OpenSSH客户端的相应文件相同。 OpenSSH's sshd manual page 中解释了它的格式, SSH 已知主机文件格式部分:

Each line in these files contains the following fields: markers (optional), hostnames, bits, exponent, modulus, comment. The fields are separated by spaces.

这实际上只适用于 SSH 1 RSA key 。对于 SSH 2 key ,您有一个类型标识符(ecdsa-sha2-nistp256ecdsa-sha2-nistp384ecdsa-sha2-nistp521ssh-dssssh-rsa),然后是 base-64 编码形式的 key 。 (请参阅同一手册页中的授权 key 文件)。 (我认为 JSch 只支持 DSA 和 RSA key 格式,不支持 ECDSA。)

Note that the lines in these files are typically hundreds of characters long, and you definitely don't want to type in the host keys by hand. Rather, generate them by a script, ssh-keyscan(1) or by taking /etc/ssh/ssh_host_key.pub and adding the host names at the front. ssh-keygen(1) also offers some basic automated editing for ~/.ssh/known_hosts including removing hosts matching a host name and converting all host names to their hashed representations.

关于c# - JSch 和 sharpSSH 的主要文件格式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8114903/

相关文章:

C# - Winform Timer - 处理和清空计时器

java - 从 testng.xml 运行测试用例时如何解决 SessionID=null 问题

java - jSch 中 b/w ChannelSftp 的 lstat() 和 stat() 方法的区别

c# - SSL 握手从 asp.net 应用程序失败 - 在浏览器中工作

c# - 如何从 TabCointainer (AjaxToolKit) 中选择一个选项卡

java - 多个线程使用数据库 DAO 类方法获取的相同值

java - Kendo UI 网格自定义数据源 URL

python - "ssh"Paramiko 中的等效代理命令

windows - Perl - 无法在 Windows 上安装 Net::SSH2

c# - 使用反射获取字典值