Skip to content

Can't create a class instance of PrivateKeyFile  #728

Closed

Description

@orionplus

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!

Activity

  1. darinkes commented on Sep 11, 2020

    @darinkes
    Collaborator

    PrivateKey != HostKey.
    You have to wait for this MR to be merged: #614

  2. orionplus commented on Sep 11, 2020

    @orionplus
    Author

    Thanks for the prompt reply. What is the proper solution would be until that merge's done?

  3. darinkes commented on Sep 11, 2020

    @darinkes
    Collaborator

    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 pem should work.

    Or you use ED25519 via: $ ssh-keygen -t ed25519

  4. orionplus commented on Sep 16, 2020

    @orionplus
    Author

    @darinkes Thanks!

  5. hhyyrylainen commented on Aug 15, 2021

    @hhyyrylainen

    With ecdsa keys I got the following error:

    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)
    

    Only ed25519 key seems to load correctly.

  6. darinkes commented on Aug 16, 2021

    @darinkes
    Collaborator

    The method or operation is not implemented.

    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.

  7. hhyyrylainen commented on Aug 16, 2021

    @hhyyrylainen

    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.117 installed.

  8. darinkes commented on Aug 16, 2021

    @darinkes
    Collaborator

    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.

  9. scott-xu commented on Sep 1, 2024

    @scott-xu
    Collaborator

    openssh key type: ecdsa-sha2-nistp521 is not supported

    The issue should be fixed by #614

    System.NotImplementedException: The method or operation is not implemented.

    The issue should be fixed by #1461

    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.117 installed.

    On Mac OS X and Linux, JetBrains Rider defaults to Mono’s csharp. 1

    Footnotes

    1. https://www.jetbrains.com/help/rider/CSHARP_Interactive.html ↩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions