mono / ngit

Automated jgit port to c#
261 stars 151 forks source link

Algorithm negotiation fail #82

Open ymcymc opened 5 years ago

ymcymc commented 5 years ago

Exception: "git@github.com:username/project.git: Algorithm negotiation fail" Code:

public class CustomConfigSessionFactory : JschConfigSessionFactory { public string PrivateKey { get; set; } public string PublicKey { get; set; }

protected override void Configure(OpenSshConfig.Host hc, Session session)
{
     var config = new Properties();
     config["StrictHostKeyChecking"] = "no";
     config["PreferredAuthentications"] = "publickey";
     session.SetConfig(config);

     var jsch = this.GetJSch(hc, FS.DETECTED);
     jsch.AddIdentity("KeyPair", Encoding.UTF8.GetBytes(PrivateKey), Encoding.UTF8.GetBytes(PublicKey), Encoding.UTF8.GetBytes("netbrain"));
}

}

var customConfigSessionFactory = new CustomConfigSessionFactory(); customConfigSessionFactory.PrivateKey = File.ReadAllText(@"D:\id_rsa"); customConfigSessionFactory.PublicKey = File.ReadAllText(@"D:\id_rsa.pub");

NGit.Transport.JschConfigSessionFactory.SetInstance(customConfigSessionFactory); var git = NGit.Api.Git.CloneRepository() .SetDirectory(new Sharpen.FilePath(@"d:\abcde"))
.SetURI("git@github.com:username/project.git") .Call();