哪一种格式应该是LibGit2的SSH私钥LibGit2Sharp(+ SSH) [英] Which format should be SSH private key for LibGit2 LibGit2Sharp (+SSH)

查看:524
本文介绍了哪一种格式应该是LibGit2的SSH私钥LibGit2Sharp(+ SSH)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个使用LibGit2Sharp-Ssh的.Net / C#应用程序克隆了一个SSH私钥问题和LibGit2Sharp-Ssh。一个Git仓库。



我需要使用SSH(https和用户/密码不是一个选项),我也有一个有效的密钥,我的代码如下所示:

  CloneOptions选项= new CloneOptions 
{
Checkout = false,
CredentialsProvider =(url,user,cred)=>新的SshUserKeyCredentials()
{
PrivateKey = privateKey,
Passphrase =密码,
PublicKey = publicKey,
Username =git
}
};
var clone = LibGit2Sharp.Repository.Clone(remoteUrl,localPath,options);

privateKey 指向私钥文件
$ b 当执行克隆时,我得到:

  LibGit2Sharp.LibGit2SharpException:无法验证SSH会话:无效的密钥数据,而不是base64编码

我尝试了所有可以用PuttyGen创建的私钥格式,但我总是得到相同的结果。



什么可能是这个问题,或者我需要什么格式来创建私钥文件?



我的OpenSSH格式的键看起来像(截断):

  ----- BEGIN RSA PRIVATE KEY ----- 
Proc-Type:4,ENCRYPTED
DEK - 信息:DES-EDE3-CBC,27A4E70608469318

<关键数据,如sdhsdcQEHBg3uzfb ...>
-----完RSA PRIVATE KEY -----


解决方案

privateKey指向OpenSSH格式的私钥文件。


privateKey 需要指向某个键的,而不是路径。您需要读取密钥文件并将内容放入字符串中,您可以将它传递给 privateKey


I´m kind of stuck with an SSH private key issue and LibGit2Sharp-Ssh.

I have a .Net/C# application that uses LibGit2Sharp-Ssh to clone a Git repository.

I need to use SSH (https with user/password is not an option) and I also have a valid key, which is already working e.g. with Teamcity.

My code looks like this:

CloneOptions options = new CloneOptions
{
     Checkout = false,
     CredentialsProvider = (url, user, cred) => new SshUserKeyCredentials()
     {
          PrivateKey = privateKey,
          Passphrase = passphrase,
          PublicKey = publicKey,
          Username = "git"
     }
};
var clone = LibGit2Sharp.Repository.Clone(remoteUrl, localPath, options);

privateKey points to a private key file in "OpenSSH" format.

When Clone is executed i get:

LibGit2Sharp.LibGit2SharpException: "Failed to authenticate SSH session: Invalid key data, not base64 encoded"

I've tried all of the private key formats I could create with PuttyGen, but I always get the same result.

What might be the issue or in what format do I need to create the private key file?

My OpenSSH-format key looks like (truncated):

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,27A4E70608469318

<Key-Data, like "sdhsdcQEHBg3uzfb...">
-----END RSA PRIVATE KEY-----

解决方案

privateKey point to a private key file in "OpenSSH" format.

privateKey needs to point to a key, not a path to a key. You need to read the key file and place the contents into a string that you can pass to privateKey.

这篇关于哪一种格式应该是LibGit2的SSH私钥LibGit2Sharp(+ SSH)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆