c#中的ppk文件中的私有密钥文件无效

发布于 2025-01-17 22:43:01 字数 534 浏览 3 评论 0原文

我正在编写一个测试用例,尝试使用密码和私钥文件连接到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不即不离 2025-01-24 22:43:01

这是因为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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文