I have an application in .NET MAUI that connects to a server via sftp and downloads a file. When debugging, everything works as expected. But as soon as I release the app for Android (target V.13, min V.9), I get the following stacktrace when connecting to the server:
Could not create HashAlgorithm from `SHA512`. Arg_ParamName_Name, hashAlgorithmName at Renci.SshNet.Security.Cryptography.RsaDigitalSignature..ctor(RsaKey rsaKey, HashAlgorithmName hashAlgorithmName) at Renci.SshNet.PrivateKeyFile.Open(Stream privateKey, String passPhrase) at Renci.SshNet.PrivateKeyFile..ctor(Stream privateKey, String passPhrase)
This is the code I am using to connect to the server:
public void Connect()
{
MemoryStream keyStream = new(Encoding.ASCII.GetBytes(privateKey));
keyFile = new PrivateKeyFile(keyStream, privateKeyPassword);
PrivateKeyConnectionInfo keyConnectionInfo = new(host, port, username, keyFile);
client = new SftpClient(keyConnectionInfo);
client.Connect();
}
As suggested by Jason, it was a linker issue. To solve this, I disabled trimming and aot for the release.
Project Properties -> Android -> Options -> Enable AOT compilation & Enable trimming