c#中的ppk文件中的私有密钥文件无效
我正在编写一个测试用例,尝试使用密码和私钥文件连接到 SFTP 但上面的异常
是我尝试过的代码
public void ConnectToSFTPTest()
{
var filename = @"C:\PvtKey.ppk";
var pk = new PrivateKeyFile(filename, "passphrase"); --here i am getting exception
var keyFiles = new[] { pk };
var client = new SftpClient("hostname", 22, "username", keyFiles);
client.Connect();
if(client.IsConnected)
{
client.Disconnect();
}
Assert.True(true);
}
任何人都可以帮助我让它工作我的文件是 ppk
I am writing a test case where i am trying to connect to SFTP using passphrase and Private key file
but getting above exception
here is my code what i have tried
public void ConnectToSFTPTest()
{
var filename = @"C:\PvtKey.ppk";
var pk = new PrivateKeyFile(filename, "passphrase"); --here i am getting exception
var keyFiles = new[] { pk };
var client = new SftpClient("hostname", 22, "username", keyFiles);
client.Connect();
if(client.IsConnected)
{
client.Disconnect();
}
Assert.True(true);
}
Can anybody help me to get it working my file is ppk
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为PPK(Putty Private Key)是一种由Putty和Putty的应用程序使用的无标准格式,您使用的库需要OpenSSH格式的键。
因此,您需要使用puttygen,然后加载ppk文件,然后以openssh格式导出文件(转换>导出openssh键)也保存了公共密钥文件,这将提供一个转换后的文件,一个人可以用来获取数据
This is because a PPK (putty private key) is a none standard format that is used by PuTTY and putty based applications, the library you're using requires an OpenSSH formatted key.
So you need to use PuTTYgen then load the PPK file and then export the file in OpenSSH format (Conversions > Export OpenSSH Key) also save the public key file this will give a converted file which one can use to fetch the data