.netsftp.net-8.0diffie-hellmanrebex

Getting CryptographicException "Negotiation failed. Unsupported instance of ECDiffieHellman algorithm." while using SFTP to send a file in .NET 8


I am getting the exception below while trying to use SFTP client to send a file. It used to work earlier but I am getting this exception since I migrated to .NET 8.

Negotiation failed. Unsupported instance of ECDiffieHellman algorithm.

Is there anything specific to SFTP that must be done in .NET 8 to fix this issue?

Here is the code snippet for reference.

using (var client = new Sftp())
{
    var privateKey = KeyFromString(Configuration.KeyString);
    var stream = StreamFromString(contents);
    client.Connect(Configuration.Url, Configuration.Port);
    client.Login(Configuration.User, Configuration.Password, privateKey);
    client.PutFile(stream, filename);
}

I tried to check for any guidelines for using SFTP in .NET 8 but could not find anything relevant.

Here is the stack trace if it helps, updated to hide sensitive information:

Inner exception Rebex.Net.SftpException handled at PutFile:
   at Rebex.Net.Sftp.viema (Rebex.Sftp undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
   at Rebex.Net.Sftp.mksfi (Rebex.Sftp undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
   at Rebex.Net.Sftp.Connect (Rebex.Sftp undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
   at PutFile 
Inner exception Rebex.Net.SshException handled at Rebex.Net.Sftp.viema:
   at Rebex.Net.SshSession.lawoz (Rebex.Networking undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
   at Rebex.Net.SshSession.Negotiate (Rebex.Networking undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
   at Rebex.Net.Sftp+ymnzg.zbkwa.igvda (Rebex.Sftp undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
   at Rebex.Net.Sftp.viema (Rebex.Sftp undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
Inner exception System.Security.Cryptography.CryptographicException handled at Rebex.Net.SshSession.lawoz:
   at ymnzg.aoqsw.kaxgn (Rebex.Common undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
   at ymnzg.aoqsw.kiovp (Rebex.Common undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
   at ymnzg.lmfzi.bltdt (Rebex.Common undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
   at Rebex.Security.Cryptography.AsymmetricKeyAlgorithm.scqfy (Rebex.Common undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
   at ymnzg.yajog.dlafz (Rebex.Networking undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
   at Rebex.Net.SshSession.lawoz (Rebex.Networking undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)

Solution

  • This is caused by a compatibility issue between old versions of Rebex SFTP and .NET 7/8's ECDiffieHellman class. This issue was fixed in Rebex SFTP v6.0.8181. That version might work with .NET 8, but is not officially supported.

    The first version of Rebex SFTP that officially supports .NET 8 is Rebex SFTP v7.0.8720. Previous versions have not been tested with .NET 8 because it was not available yet.

    You are using Rebex SFTP v5.0.7733, which was published in early 2021. It supported .NET 5, but has not been tested with .NET 6, 7, or 8 and is not supported on any these platforms.