Description
DOTNETCORE 3.1, with SSH.NET
I can successfully connect to a remote host with username and private key using Filezilla.
The same credentials and private key used with SSH.NET give me an exception.
The Exception seems to be some internal issue and not sure what to do to address it.
Can anyone help?
Exception:
Accessing a hash algorithm by manipulating the HashName property is not supported on this platform. Instead, you must instantiate one of the supplied subtypes (such as HMACSHA1.)
" at System.Security.Cryptography.HMAC.HashFinal() in //src/System.Security.Cryptography.Primitives/src/System/Security/Cryptography/HMAC.cs:line 68\r\n at Renci.SshNet.Security.Cryptography.HMACSHA1.HashFinal()\r\n at System.Security.Cryptography.HashAlgorithm.CaptureHashCodeAndReinitialize() in //src/System.Security.Cryptography.Primitives/src/System/Security/Cryptography/HashAlgorithm.cs:line 115\r\n at Renci.SshNet.Session.SendMessage(Message message)\r\n at Renci.SshNet.Session.Connect()\r\n at Renci.SshNet.BaseClient.CreateAndConnectSession()\r\n at Renci.SshNet.BaseClient.Connect()\r\n at ... (my code)
Exception type:
{Name = "PlatformNotSupportedException" FullName = "System.PlatformNotSupportedException"} Assembly: {System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e} AssemblyQualifiedName: "System.PlatformNotSupportedException, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" Attributes: Public | Serializable | BeforeFieldInit BaseType: {Name = "NotSupportedException" FullName = "System.NotSupportedException"} Cache: {System.RuntimeType.RuntimeTypeCache} CacheIfExists: {System.RuntimeType.RuntimeTypeCache} ContainsGenericParameters: false CustomAttributes: Count = 4 DeclaredConstructors: {System.Reflection.ConstructorInfo[4]} DeclaredEvents: {System.Reflection.EventInfo[0]} DeclaredFields: {System.Reflection.FieldInfo[0]} DeclaredMembers: {System.Reflection.MemberInfo[4]} DeclaredMethods: {System.Reflection.MethodInfo[0]} DeclaredNestedTypes: {System.Reflection.TypeInfo.<get_DeclaredNestedTypes>d__22} DeclaredProperties: {System.Reflection.PropertyInfo[0]} DeclaringMethod: '((System.RuntimeType)exception.GetType()).DeclaringMethod' threw an exception of type 'System.InvalidOperationException' }
CODE:
` SftpClient client = null;
MemoryStream stream = null;
StreamWriter writer = null;
try
{
stream = new MemoryStream();
writer = new StreamWriter(stream);
writer.Write(
"-----BEGIN RSA PRIVATE KEY-----" + "\n" +
"MIIEpAIBAAKCAQEAsR7i+1kbPfZj2foKjRzM1gpf0OcjD2cNP/wBmwGmOjdQoW5/" + "\n" +
...
"KcsxONtrmHQGPR8Oh8v94eL2pAC0rZ3rXb9YwVMpWBDyR6WGrw9OeQ==" + "\n" +
"-----END RSA PRIVATE KEY-----");
writer.Flush();
stream.Position = 0;
var keys = new PrivateKeyFile[] { new PrivateKeyFile(stream) };
using var client = new SftpClient(this.config.Host, this.config.Port, this.config.Username, this.config.Password);
client.Connect();
return client.ListDirectory(remoteDirectory);
}
catch (Exception exception)
{
this.logger.LogError(exception, $"Failed to list directory: {remoteDirectory}");
return null;
}
finally
{
stream?.Close();
writer?.Close();
client?.Disconnect();
}`