C# 在使用 SSH FTP 时出现"DER length is '95' and cannot be more than 4 bytes"错误



代码:

var connectionInfo = new ConnectionInfo(Utilities.GetConfigValueByKey(processName + Constants.KEY_FTP_SERVER), Convert.ToInt32(Utilities.GetConfigValueByKey(processName + Constants.KEY_FTP_PORT)),
                Utilities.GetConfigValueByKey(processName + Constants.KEY_FTP_USERID),
                new PasswordAuthenticationMethod(Utilities.GetConfigValueByKey(processName + Constants.KEY_FTP_USERID)
                                               , Utilities.GetConfigValueByKey(processName + Constants.KEY_FTP_PWD)),
                new PrivateKeyAuthenticationMethod(Utilities.GetConfigValueByKey(processName + Constants.KEY_FTP_USERID),
                     new PrivateKeyFile(File.OpenRead(@"C:JobsTestid_rsa"), "testpwd"))
            );

它在私钥文件失败,有人可以帮助我做错了什么。

我已经尝试将文件名作为文本文件,但仍然没有运气。

对于历史,如果可以帮助某人。对我来说,问题在于密码。有一个额外的字符(回车),它使制动器成为钥匙访问并显示此错误

我收到了同样的错误,因为我对私钥文件使用了错误的密码短语。

new PrivateKeyFile(path, passphrase)

此外,Renci SSH.NET 想要一个OpenSSH格式的密钥(以-----BEGIN RSA PRIVATE KEY-----开头)。您可以使用PuTTYgen ->转换->导出OpenSSH密钥来创建一个。

相关内容

最新更新