-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add samples and better documentation
- Loading branch information
Showing
7 changed files
with
157 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
// Use IntelliSense to find out which attributes exist for C# debugging | ||
// Use hover for the description of the existing attributes | ||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": ".NET Core Launch (console)", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build", | ||
// If you have changed target frameworks, make sure to update the program path. | ||
"program": "${workspaceFolder}/sample/bin/Debug/netcoreapp2.0/sample.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/sample", | ||
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window | ||
"console": "internalConsole", | ||
"stopAtEntry": false, | ||
"internalConsoleOptions": "openOnSessionStart" | ||
}, | ||
{ | ||
"name": ".NET Core Attach", | ||
"type": "coreclr", | ||
"request": "attach", | ||
"processId": "${command:pickProcess}" | ||
} | ||
,] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/sample/sample.csproj" | ||
], | ||
"problemMatcher": "$msCompile" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,71 @@ | |
|
||
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. | ||
|
||
# References | ||
## Supported Platforms | ||
|
||
- .NET 4.5 (Desktop / Server) | ||
- .NET Standard 2.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(2048); | ||
var privateKey = keygen.ToPrivateKey(); | ||
Console.WriteLine(privateKey); | ||
var publicSshKey = keygen.ToRfcPublicKey(); | ||
Console.WriteLine(publicSshKey); | ||
var publicSshKeyWithComment = keygen.ToRfcPublicKey("[email protected]"); | ||
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("[email protected]") | ||
|
||
``` | ||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzU7/0XZeVlVpVYRRh9 | ||
... | ||
+ohFsbcbAMcfLWGUdouyHvLvF21G0z50z2i2CrU7WW4WdrGGfxhU3TeRTXd7Skwk/K7iBBn3oc/xct [email protected] | ||
``` | ||
|
||
## References | ||
|
||
- Exporting Private Key: https://stackoverflow.com/a/23739932 | ||
- Exporting Public Key: https://stackoverflow.com/a/25591659 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
|
||
namespace SshKeyGenerator | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var keygen = new SshKeyGenerator(2048); | ||
|
||
var privateKey = keygen.ToPrivateKey(); | ||
Console.WriteLine(privateKey); | ||
|
||
var publicSshKey = keygen.ToRfcPublicKey(); | ||
Console.WriteLine(publicSshKey); | ||
|
||
var publicSshKeyWithComment = keygen.ToRfcPublicKey("[email protected]"); | ||
Console.WriteLine(publicSshKeyWithComment); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'"> | ||
<ProjectReference Include="..\src\SshKeyGenerator.csproj" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters