You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't create a class instance of PrivateKeyFile #728
I'm using version 2020.0.0-beta1.
Created the key pair with the command: ssh-keygen -t ecdsa -b 521
During the object creation
PrivateKeyFile keyFile = new PrivateKeyFile("c:..\id_ecdsa_private.key","passphrase")
I'm getting the error:
openssh key type: ecdsa-sha2-nistp521 is not supported
at Renci.SshNet.PrivateKeyFile.ParseOpenSshV1Key(Byte[] keyFileData, String passPhrase)
at Renci.SshNet.PrivateKeyFile.Open(Stream privateKey, String passPhrase)
at Renci.SshNet.PrivateKeyFile..ctor(String fileName, String passPhrase)
at Renci.SshNet.PrivateKeyFile..ctor(String fileName)
at Onboarding.Services.SFTPService.d__7.MoveNext() in C:\Projects...\SFTPService.cs:line 65
The documentation says SSH.NET supports the following host key algorithms:
...
ecdsa-sha2-nistp521
...
Can anyone tell me please what is wrong?
Thanks!
ECDSA Keys are currently just supported in OpenSSL-Format. ssh-keygen generates them in OpenSSH-Format by default.
So a key generated with $ ssh-keygen -t ecdsa -b 521 -m pem should work.
System.NotImplementedException: The method or operation is not implemented.
at System.Security.Cryptography.ECDsa.Create (System.Security.Cryptography.ECParameters parameters) [0x00000] in <d9f4d70345484e55bbf6c1ef353f07c4>:0
at Renci.SshNet.Security.EcdsaKey.Import (System.String curve_oid, System.Byte[] publickey, System.Byte[] privatekey) [0x0007e] in <c7169cd606324a41b931acc40c516428>:0
at Renci.SshNet.Security.EcdsaKey..ctor (System.Byte[] data) [0x000f0] in <c7169cd606324a41b931acc40c516428>:0
at Renci.SshNet.PrivateKeyFile.Open (System.IO.Stream privateKey, System.String passPhrase) [0x00322] in <c7169cd606324a41b931acc40c516428>:0
at Renci.SshNet.PrivateKeyFile..ctor (System.String fileName, System.String passPhrase) [0x00023] in <c7169cd606324a41b931acc40c516428>:0
at Renci.SshNet.PrivateKeyFile..ctor (System.String fileName) [0x00000] in <c7169cd606324a41b931acc40c516428>:0
at Submission#30+<<Initialize>>d__0.MoveNext () [0x00008] in <e93e87d6d7854cc0919a6dcae8d7157b>:0
That was in PEM format, and (without specifying -m pem to key generation), I got this error:
Renci.SshNet.Common.SshException: openssh key type: ecdsa-sha2-nistp521 is not supported
+ Renci.SshNet.PrivateKeyFile.ParseOpenSshV1Key(byte[], string)
+ Renci.SshNet.PrivateKeyFile.Open(System.IO.Stream, string)
+ Renci.SshNet.PrivateKeyFile..ctor(string, string)
+ Renci.SshNet.PrivateKeyFile..ctor(string)
Activity
darinkes commentedon Sep 11, 2020
PrivateKey != HostKey.
You have to wait for this MR to be merged: #614
orionplus commentedon Sep 11, 2020
Thanks for the prompt reply. What is the proper solution would be until that merge's done?
darinkes commentedon Sep 11, 2020
You can create a key with the methods listed here: https://github.com/sshnet/SSH.NET#public-key-authentication.
ECDSA Keys are currently just supported in OpenSSL-Format. ssh-keygen generates them in OpenSSH-Format by default.
So a key generated with
$ ssh-keygen -t ecdsa -b 521 -m pemshould work.Or you use ED25519 via:
$ ssh-keygen -t ed25519orionplus commentedon Sep 16, 2020
@darinkes Thanks!
hhyyrylainen commentedon Aug 15, 2021
With ecdsa keys I got the following error:
That was in PEM format, and (without specifying
-m pemto key generation), I got this error:Only
ed25519key seems to load correctly.darinkes commentedon Aug 16, 2021
That sounds like Mono, not .NET Correct?
https://github.com/mono/mono/blob/main/mcs/class/referencesource/System.Core/System/Security/Cryptography/ECDsa.cs#L31
ed25519 is done in SSH.NET, ECDsa requires .NET or netstandard functionality.
See the Readme, Mono is not supported. Also cause most of the Crypto we need just throws NotImplementedExceptions.
hhyyrylainen commentedon Aug 16, 2021
I'm using
.NET SDK (5.0.205)on Linux.Edit: I used C# Interactive from Rider, where I'm not 100% sure it uses that version as I also have SDK version
3.1.117installed.darinkes commentedon Aug 16, 2021
Weird. Cant see why official .NET should raise this exception.
In .NET Ecdsa.Create(ECParameters) is implemented since ages, see:
https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.ecdsa.create?view=net-5.0#System_Security_Cryptography_ECDsa_Create_System_Security_Cryptography_ECParameters_
Just seen this error with Mono so far. Using SSH.NET myself on various linux systems, all work fine ECDsa and .NET.
scott-xu commentedon Sep 1, 2024
The issue should be fixed by #614
The issue should be fixed by #1461
On Mac OS X and Linux, JetBrains Rider defaults to Mono’s csharp. 1
Footnotes
https://www.jetbrains.com/help/rider/CSHARP_Interactive.html ↩