Search code examples
c#.netsshsftpssh.net

C# Update cipher Renci.SshNet


We are using Renci.SshNet C# library to connect to SFTP server.

Today connection on code line

client.Connect();

to server stopped working with error message:

Unhandled Exception: Renci.SshNet.Common.SshConnectionException: The connection was closed by the server: Your cipher needs to be updated: https://developer.eba y.com/devzone/merchant-products/mipng/user-guide-en/default.html#advanced-featur es.html . please contact MIP Support for help (ByApplication). at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)

I installed latest SSH.NET and .NET Framework, and still same error

Could anyone help what needs to be done to fix that error?

Appreciate any help


Solution

  • I encountered the same issue. Here is the fix for SSH.NET client w/ C#

    var connectionInfo = new ConnectionInfo(...);
    
    var deprecatedMacs = new List<string>
      {
        "hmac-md5",
        "hmac-md5-96",
        "[email protected]",
        "hmac-sha1-96",
        "hmac-sha2-256-96",
        "hmac-sha2-512-96"
      };
    
      var deprecatedCiphers = new List<string>
      {
        "aes128-cbc",
        "aes192-cbc",
        "aes256-cbc",
        "blowfish-cbc",
        "3des-cbc",
        "3des-ctr",
        "arcfour",
        "arcfour128",
        "arcfour256"
      };
    
      // remove deprecated macs
      foreach(var deprecatedMac in deprecatedMacs)
      {
        connectionInfo.HmacAlgorithms.Remove(deprecatedMac);
      }
    
      // remove deprecated ciphers
      foreach(var deprecatedCipher in deprecatedCiphers)
      {
        connectionInfo.Encryptions.Remove(deprecatedCipher);
      }
    
      using (var client = new SftpClient(connectionInfo))
      {
        try
        {
          
          client.Connect(); // Should work now
    
        }
    
        catch (Exception ex)
        {
            // ...
        }
      }