GithubHelp home page GithubHelp logo

darinkes / sshnet.keygen Goto Github PK

View Code? Open in Web Editor NEW
5.0 4.0 1.0 151 KB

SSH.NET Extension to generate and export Authentication Keys in OpenSSH and PuTTY Format. ๐Ÿ”‘

License: MIT License

C# 99.42% Shell 0.58%
ssh sshnet keygen nuget csharp csharp-library dotnet putty puttygen

sshnet.keygen's Introduction

SshNet.Keygen

SSH.NET Extension to generate and export Authentication Keys in OpenSSH and PuTTY v2 and v3 Format.

License NuGet Nuget

.NET-Ubuntu .NET-Windows NuGet

Status

WIP

.NET Frameworks

  • .NET 4.8
  • netstandard 2.0

Keys

  • ssh-ed25519
  • ecdsa-sha2-nistp256
  • ecdsa-sha2-nistp384
  • ecdsa-sha2-nistp521
  • ssh-rsa with 2048, 3072, 4096 or 8192 KeyLength

Fingerprinting

  • Get Key Fingerprint as MD5, SHA1, SHA256, SHA384 or SHA512

Key Encryption

OpenSSH

  • None
  • AES256-ctr
  • AES256-cbc

PuTTY

  • None
  • AES256-cbc

Usage Examples

Generate an RSA-2048 Key in File, Show the Public Key and Connect with the Private Key

var key = SshKey.Generate("test.key", FileMode.Create);

var publicKey = key.ToPublic();
var fingerprint = key.Fingerprint();

Console.WriteLine("Fingerprint: {0}", fingerprint);
Console.WriteLine("Add this to your .ssh/authorized_keys on the SSH Server: {0}", publicKey);
Console.ReadLine();

using var client = new SshClient("ssh.foo.com", "root", key);
client.Connect();
Console.WriteLine(client.RunCommand("hostname").Result);

Generate an RSA-2048 Key in PuTTY File, Show the Public Key and Connect with the Private Key

var keyInfo = new SshKeyGenerateInfo
{
    KeyFormat = SshKeyFormat.PuTTYv3
};
var key = SshKey.Generate("test.ppk", FileMode.Create, keyInfo);

var publicKey = key.ToPublic(SshKeyFormat.OpenSSH);
var fingerprint = key.Fingerprint();

Console.WriteLine("Fingerprint: {0}", fingerprint);
Console.WriteLine("Add this to your .ssh/authorized_keys on the SSH Server: {0}", publicKey);
Console.ReadLine();

using var client = new SshClient("ssh.foo.com", "root", key);
client.Connect();
Console.WriteLine(client.RunCommand("hostname").Result);

Generate an password protected RSA-2048 Key in File, Show the Public Key and Connect with the Private Key

var keyInfo = new SshKeyGenerateInfo
{
    Encryption = new SshKeyEncryptionAes256("12345")
};
var key = SshKey.Generate("test.key", FileMode.Create, keyInfo);

var publicKey = key.ToPublic();
var fingerprint = key.Fingerprint();

Console.WriteLine("Fingerprint: {0}", fingerprint);
Console.WriteLine("Add this to your .ssh/authorized_keys on the SSH Server: {0}", publicKey);
Console.ReadLine();

using var client = new SshClient("ssh.foo.com", "root", key);
client.Connect();
Console.WriteLine(client.RunCommand("hostname").Result);

Generate an password protected RSA-2048 Key in Putty v2 File, Show the Public Key and Connect with the Private Key

var keyInfo = new SshKeyGenerateInfo
{
    KeyFormat = SshKeyFormat.PuTTYv2,
    Encryption = new SshKeyEncryptionAes256("12345")
};
var key = SshKey.Generate("test.ppk", FileMode.Create, keyInfo);

var publicKey = key.ToPublic(SshKeyFormat.OpenSSH);
var fingerprint = key.Fingerprint();

Console.WriteLine("Fingerprint: {0}", fingerprint);
Console.WriteLine("Add this to your .ssh/authorized_keys on the SSH Server: {0}", publicKey);
Console.ReadLine();

using var client = new SshClient("ssh.foo.com", "root", key);
client.Connect();
Console.WriteLine(client.RunCommand("hostname").Result);

Generate an password protected RSA-2048 Key in Putty v3 File with own Argon Options, Show the Public Key and Connect with the Private Key

var keyInfo = new SshKeyGenerateInfo
{
    KeyFormat = SshKeyFormat.PuTTYv3,
    Encryption = new SshKeyEncryptionAes256("12345", new PuttyV3Encryption { KeyDerivation = ArgonKeyDerivation.Argon2d, Iterations = 64, DegreeOfParallelism = 44 })
};
var key = SshKey.Generate("test.ppk", FileMode.Create, keyInfo);

var publicKey = key.ToPublic(SshKeyFormat.OpenSSH);
var fingerprint = key.Fingerprint();

Console.WriteLine("Fingerprint: {0}", fingerprint);
Console.WriteLine("Add this to your .ssh/authorized_keys on the SSH Server: {0}", publicKey);
Console.ReadLine();

using var client = new SshClient("ssh.foo.com", "root", key);
client.Connect();
Console.WriteLine(client.RunCommand("hostname").Result);

Generate an RSA-2048 Key, Show the Public Key and Connect with the Private Key

var key = SshKey.Generate();

var publicKey = key.ToPublic();
var fingerprint = key.Fingerprint();

Console.WriteLine("Fingerprint: {0}", fingerprint);
Console.WriteLine("Add this to your .ssh/authorized_keys on the SSH Server: {0}", publicKey);
Console.ReadLine();

using var client = new SshClient("ssh.foo.com", "root", key);
client.Connect();
Console.WriteLine(client.RunCommand("hostname").Result);

Generate an RSA-8192 Key, Show the Public Key and Connect with the Private Key

var keyInfo = new SshKeyGenerateInfo
{
    KeyLength = 8192
};
var key = SshKey.Generate(keyInfo);

var publicKey = key.ToPublic();
var fingerprint = key.Fingerprint();

Console.WriteLine("Fingerprint: {0}", fingerprint);
Console.WriteLine("Add this to your .ssh/authorized_keys on the SSH Server: {0}", publicKey);
Console.ReadLine();

using var client = new SshClient("ssh.foo.com", "root", key);
client.Connect();
Console.WriteLine(client.RunCommand("hostname").Result);

Generate an ECDSA-256 Key, Show the Public Key and Connect with the Private Key

var keyInfo = new SshKeyGenerateInfo(SshKeyType.ECDSA);
var key = SshKey.Generate(keyInfo);

var publicKey = key.ToPublic();
var fingerprint = key.Fingerprint();

Console.WriteLine("Fingerprint: {0}", fingerprint);
Console.WriteLine("Add this to your .ssh/authorized_keys on the SSH Server: {0}", publicKey);
Console.ReadLine();

using var client = new SshClient("ssh.foo.com", "root", key);
client.Connect();
Console.WriteLine(client.RunCommand("hostname").Result);

Generate an ED25519 Key, Show the Public Key and Connect with the Private Key

var keyInfo = new SshKeyGenerateInfo(SshKeyType.ED25519);
var key = SshKey.Generate(keyInfo);

var publicKey = key.ToPublic();
var fingerprint = key.Fingerprint();

Console.WriteLine("Fingerprint: {0}", fingerprint);
Console.WriteLine("Add this to your .ssh/authorized_keys on the SSH Server: {0}", publicKey);
Console.ReadLine();

using var client = new SshClient("ssh.foo.com", "root", key);
client.Connect();
Console.WriteLine(client.RunCommand("hostname").Result);

Export an existing Key from SSH.NET

var keyFile = new PrivateKeyFile("test.key");

var privateKey = keyFile.ToOpenSshFormat();
var publicKey =  keyFile.ToPublic();

Console.WriteLine("Private Key: {0}", privateKey);
Console.WriteLine("Public Key: {0}", publicKey);

Export an existing Key from SSH.NET with Encryption

var keyFile = new PrivateKeyFile("test.key");

var privateKey = keyFile.ToOpenSshFormat("12345");
var puttyKey = keyFile.ToPuttyFormat("12345");
var publicKey =  keyFile.ToPublic();
var puttyPublicKey =  keyFile.ToPuttyPublicFormat();

Console.WriteLine("Private Key: {0}", privateKey);
Console.WriteLine("Putty Private Key: {0}", puttyKey);
Console.WriteLine("Public Key: {0}", publicKey);
Console.WriteLine("Putty Public Key: {0}", puttyPublicKey);

sshnet.keygen's People

Contributors

darinkes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

spektor56

sshnet.keygen's Issues

Generate Password-protected file generates normal key

When generating a key pair with the following code:

var keyInfo = new SshKeyGenerateInfo
{
    KeyFormat = SshKeyFormat.PuTTY,
    Encryption = new SshKeyEncryptionAes256("12345")
};
var key = SshKey.Generate("test.ppk", FileMode.Create, keyInfo);

var publicKey = key.ToPublic();
var fingerprint = key.Fingerprint();
var putty = key.ToPuttyFormat();

Console.WriteLine(putty);

The output of the putty key file says there is no encryption on the file, and I can even use no passphrase to connect to the server.

PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: username@devicename
Public-Lines: 6
AAAAB3NzaC1yc2EAAAADAQABAAABAQCqndBjN3SLXONx/R4LzwTRTZPqJUghtq1L
YJLPZgUqftQQ8L18c//I8EwOoVF04Qc4zSBuOhwojPA0GOrrBzyEtqKkTxRJlAOu
2Kz5dAvEhDgCH3eN4J8RoGypCaB1gTz5jW+oLvGU0fcwhJc8ocP8KrT80J1rhKGD
La36gn3QYnf3OEzXVWaT3phuPM0cv3/JZUOiFkMpfobcJw/uOqevqgbnwO7Ni5+Z
uNMi9MbDJX+zWB920jN3lscX02yP9ETW8/mjPLRMO1N28LPkp5IVjkr3PctmtND/
wWIAq3XzfWcMsxkdem9SIFdDumWO8+FNY+EqmtnnlBLaW7TvT621
Private-Lines: 14
AAABAFy7UZvbdDiaz/QQgtggOJoZ9B77DG1mgGHLp3+aD4y9Sj262wJdedSY5n29
KCzCcc5pjwraApv3nkZylJwRXs8zBMsRQBGNpULO+ZTLgenZgyeEOtKeF1bZPrXR
SakUCTQJr3pVqXAdfqCcMCcANSlFfQE70ZOyjqZhmYHiksdDGoBdDcAEr9hK06QW
QsgCLXdcqOj/CYH+3bP2rRGhdOBQ4/7cE4cRyloK6vQPrklsI59BKFQZ+eBD7t1/
/Re+xoOg4QAECkMNAkE7BfzAg3yRPyHcM9oQnmxs6jWidbuUtSymxiZTsA8UmG9V
mF1GBiSx1gXyt/pY1yraF+7eBzEAAACBAM0oPMrnR0C1vlqbkzFpYyeZJZKjRy2d
p3elclRD7gRBO11cQeFbTOSxEwdzYtXgqaREpdxddNd0AqSrisShJbjJge1BplSm
HXNXUPhF3oP+ixFQAQR+aOnsMPEpZfv8FfT+/aO3+fg1ldKOqoMkTYzVNymUbTdA
yUZaRWnOFOnLAAAAgQDU5jbFQfDEwBCwejEMNB2bIZnQZ6cipdqvD3ZfGEVKKAtz
eM9FTz/XUBoo84o4OqLcTJiByghdzxnKKBofjgN8Bc2MY577S+k6jF442QK4usi5
s+uF674sCP1gWZwKd6jezAyLaNLIN9jNaUScOO1tfUNhM2UpliQqRzb1toDWfwAA
AIAIDvVgw9pIpCPcBUmWU1hVwr83jZZqazuk5XMLBxrtKVU9cYosF3kp5sb5C5WH
knw91x08H6eT7zlCNMgBMwq197fG62F4TjZRy2hVcR/+PSqFTdVSwUYi4J5+QI7I
qYDzLEl5tMangrd4DCo4lSuBO1o+RcXtRESkuakER3JfaAECAwQFBgcICQoLDA0O
Private-MAC: 679b164a38d55c8f8b0f89b2e7d1213449bb47cb

RSA Key Encryption

Great Project! Any non synced updates to this?

I rolled some of your changes in to the current SSH.NET, but
the case:(s) for Key names are off (ie "Renci.SshNet.Security.RsaKey" vs "ssh-rsa")

Also Looking for RSA Key encryption?

Regards,
Mike

The public key format is inconsistent with the PUTTYGEN client

Reproduce code

var keyInfo = new SshKeyGenerateInfo
{
    KeyFormat = SshKeyFormat.PuTTY
};
var key = SshKey.Generate("test.ppk", FileMode.Create, keyInfo);

var publicKey = key.ToPublic();

Expect

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "Varorbc@DESKTOP-TRGK209"
AAAAB3NzaC1yc2EAAAADAQABAAABAQCvUe9d3TAZpiAn6teq9iXvXLBGsda8ARvA
Zzbp95L5GqKCib2vm0stMEh8VBk6SzZ0ZIohDqNQaGl4JSTSS6hjYMMNlgrs7Whs
6Ovsj4ciDqRmIqYHAJMJQS5S9m/hFFaoQ0CDtX4Mf29u3OnTILihRTnhnK8Rco4k
FHZS3wD8ldnFnAEBeHD0TTnnmSId0SaR4/CAdN6Foy3Sj+cBUM2oeYvGERB1lMSC
ZU2BVnu61Wh9hVHeoGP6xY+e9eKv7KuXdm2hs6sh0qCVp5O5SHEzSvBWlZdZdynD
dlJsA2HlofP0rEhIV5dZbOCkjbKzB64xCGerc12JQnY911/tRYRx
---- END SSH2 PUBLIC KEY ----

Actual

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvUe9d3TAZpiAn6teq9iXvXLBGsda8ARvAZzbp95L5GqKCib2vm0stMEh8VBk6SzZ0ZIohDqNQaGl4JSTSS6hjYMMNlgrs7Whs6Ovsj4ciDqRmIqYHAJMJQS5S9m/hFFaoQ0CDtX4Mf29u3OnTILihRTnhnK8Rco4kFHZS3wD8ldnFnAEBeHD0TTnnmSId0SaR4/CAdN6Foy3Sj+cBUM2oeYvGERB1lMSCZU2BVnu61Wh9hVHeoGP6xY+e9eKv7KuXdm2hs6sh0qCVp5O5SHEzSvBWlZdZdynDdlJsA2HlofP0rEhIV5dZbOCkjbKzB64xCGerc12JQnY911/tRYRx Varorbc@DESKTOP-TRGK209

move sshnet.puttyfile to sshnet.keygen

I also used puttyfile, but there were only two files in the project, and I found the same dependencies as the current project, Is it possible to incorporate them, even Agent, as an extension of SSH. NET.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.