SshKeyGenerator 1.1.51
dotnet add package SshKeyGenerator --version 1.1.51
NuGet\Install-Package SshKeyGenerator -Version 1.1.51
<PackageReference Include="SshKeyGenerator" Version="1.1.51" />
paket add SshKeyGenerator --version 1.1.51
#r "nuget: SshKeyGenerator, 1.1.51"
// Install SshKeyGenerator as a Cake Addin #addin nuget:?package=SshKeyGenerator&version=1.1.51 // Install SshKeyGenerator as a Cake Tool #tool nuget:?package=SshKeyGenerator&version=1.1.51
DotNet Core SSH KeyGen
After searching around for a solution to creating SSH keys using C# and dotnet core I came across the following stackoverflow posts which explain how to convert from RSACryptoServiceProvider
to values suitable for use with ssh.
Supported Platforms
- .NET 4.5 (Desktop / Server)
- .NET Standard 2.0
- .NET Standard 2.1
- .NET 5.0
- .NET 6.0
Installation
SshKeyGenerator is a library for .NET and is available on NuGet:
Install-Package SshKeyGenerator
or
dotnet add package SshKeyGenerator
Usage Example
var keygen = new SshKeyGenerator.SshKeyGenerator(2048);
var privateKey = keygen.ToPrivateKey();
Console.WriteLine(privateKey);
var publicSshKey = keygen.ToRfcPublicKey();
Console.WriteLine(publicSshKey);
var publicSshKeyWithComment = keygen.ToRfcPublicKey("user@domain.com");
Console.WriteLine(publicSshKeyWithComment);
Sample Output
keygen.ToPrivateKey()
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAs1O/9F2XlZVaVWEUYfflxx0wDG9FE09hQF2wngA6EemHpe6I
hvdwvQ7obrZ85jSYdBxBRjNAYF3T9+wU+8w6m4qZCVYvqqRjszN8j3VwUBLzWilt
...
wDGzJIkmbhANi+252pH6PAuWjZPfz8COGA6QPPH0/khpHPj1LY4mi5Ubi3YT1uRo
dOGttjtkj9fLX5IQ81G9HR0MdT1Gd4fPenYPOUCgCPB5adpT1BB+
-----END RSA PRIVATE KEY-----
keygen.ToRfcPublicKey()
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzU7/0XZeVlVpVYRRh9
...
+ohFsbcbAMcfLWGUdouyHvLvF21G0z50z2i2CrU7WW4WdrGGfxhU3TeRTXd7Skwk/K7iBBn3oc/xct generated-key
keygen.ToRfcPublicKey("user@domain.com")
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzU7/0XZeVlVpVYRRh9
...
+ohFsbcbAMcfLWGUdouyHvLvF21G0z50z2i2CrU7WW4WdrGGfxhU3TeRTXd7Skwk/K7iBBn3oc/xct user@domain.com
Export Methods
There are three methods which can be used to export SSH key data for use by other libraries such as FxSsh:
- byte[] ToBlobs : Export as Blobs
- string ToB64Blob : Export blobs as base64 string
- string ToXml : Export as XML string
Export methods usage:
// Create a new instance
var keygen = new SshKeyGenerator.SshKeyGenerator(4096);
// Get Base64 encoded keys with private key
var base64Keys = keygen.ToB64Blob(true);
// Use in a SSH server. e.g. FxSsh
var server = new SshServer();
server.AddHostKey("ssh-rsa", base64Keys);
References
- Exporting Private Key: https://stackoverflow.com/a/23739932
- Exporting Public Key: https://stackoverflow.com/a/25591659
- Exporting Public Key in RFC4716 Format: https://stackoverflow.com/a/47917364
Contributors
Thanks to the following contributors for their assistance with this library.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net452 is compatible. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5.2
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on SshKeyGenerator:
Package | Downloads |
---|---|
Slithin.Core
Package Description |
|
Test.SFTP.Server
Package Description |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on SshKeyGenerator:
Repository | Stars |
---|---|
furesoft/Slithin
A management application for the remarkable tablet
|
Version | Downloads | Last updated |
---|---|---|
1.1.51 | 291,082 | 1/29/2023 |
1.1.50 | 95,409 | 3/18/2022 |
1.1.49 | 1,304 | 3/18/2022 |
1.1.48 | 1,203 | 3/18/2022 |
1.1.47 | 1,284 | 3/18/2022 |
1.1.46 | 1,239 | 3/18/2022 |
1.1.45 | 3,541 | 2/5/2022 |
1.1.44 | 1,362 | 2/3/2022 |
1.1.43 | 1,353 | 2/3/2022 |
1.1.42 | 1,289 | 2/3/2022 |
1.1.40 | 171,944 | 3/25/2021 |
1.1.39 | 1,215 | 3/25/2021 |
1.1.38 | 5,810 | 1/16/2021 |
1.1.33 | 34,948 | 3/5/2020 |
1.1.32 | 1,426 | 3/5/2020 |
1.1.31 | 15,053 | 10/30/2019 |
1.1.19 | 4,988 | 7/21/2018 |
1.1.18 | 1,838 | 7/21/2018 |
1.1.17 | 1,804 | 7/21/2018 |
1.1.16 | 1,853 | 7/18/2018 |
1.1.15 | 1,860 | 7/18/2018 |
1.1.14 | 1,829 | 7/18/2018 |
1.1.13 | 1,858 | 7/17/2018 |
1.1.12 | 1,817 | 7/17/2018 |
1.1.11 | 15,486 | 7/17/2018 |