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 | 304,790 | 1/29/2023 |
1.1.50 | 96,164 | 3/18/2022 |
1.1.49 | 1,308 | 3/18/2022 |
1.1.48 | 1,207 | 3/18/2022 |
1.1.47 | 1,288 | 3/18/2022 |
1.1.46 | 1,243 | 3/18/2022 |
1.1.45 | 3,543 | 2/5/2022 |
1.1.44 | 1,366 | 2/3/2022 |
1.1.43 | 1,357 | 2/3/2022 |
1.1.42 | 1,293 | 2/3/2022 |
1.1.40 | 172,404 | 3/25/2021 |
1.1.39 | 1,219 | 3/25/2021 |
1.1.38 | 5,828 | 1/16/2021 |
1.1.33 | 34,961 | 3/5/2020 |
1.1.32 | 1,430 | 3/5/2020 |
1.1.31 | 15,085 | 10/30/2019 |
1.1.19 | 4,999 | 7/21/2018 |
1.1.18 | 1,842 | 7/21/2018 |
1.1.17 | 1,808 | 7/21/2018 |
1.1.16 | 1,857 | 7/18/2018 |
1.1.15 | 1,864 | 7/18/2018 |
1.1.14 | 1,833 | 7/18/2018 |
1.1.13 | 1,862 | 7/17/2018 |
1.1.12 | 1,821 | 7/17/2018 |
1.1.11 | 15,491 | 7/17/2018 |