Open
Description
Android framework version
net9.0-android
Affected platform version
.NET 9.0.100, 9.0.102
Description
Trying to perform SHA1 hash with android assembly compression disabled ComputeHash to throw an exception: [System.Security.Cryptography.CryptographicException]: Cryptography_ConcurrentUseNotSupported
Steps to Reproduce
- Create a blank .net9.0 android application
- Add msbuild property:
<AndroidEnableAssemblyCompression>false</AndroidEnableAssemblyCompression>
- Add the following code:
var hash = sha.ComputeHash(bytes); // will die here
var hi = Convert.ToHexString(hash);
Console.WriteLine("SAMPLE HASH: " + hi);
- Run in release mode
- Observe logcat for exception (shown in log output field)
Repro Sample: https://github.com/aritchie/android_net9_crypto_crash
Did you find any workaround?
No
Tried the following and causes an crypto loop internal mono crash
#if NET9_0 && ANDROID
this will cause an internal crash with mono
var hash = SHA1.HashData(bytes);
var hi = Convert.ToHexString(hash);
#endif
Relevant log output
ndroid.runtime.JavaProxyThrowable: [System.Security.Cryptography.CryptographicException]: Cryptography_ConcurrentUseNotSupported
02-04 15:00:51.928 I/MonoDroid(30757): at System.Security.Cryptography.ConcurrencyBlock.Enter + 0x1a(Unknown Source)
02-04 15:00:51.928 I/MonoDroid(30757): at System.Security.Cryptography.HashProviderDispenser+EvpHashProvider.FinalizeHashAndReset + 0x0(Unknown Source)
02-04 15:00:51.928 I/MonoDroid(30757): at System.Security.Cryptography.HashProvider.FinalizeHashAndReset + 0x13(Unknown Source)
02-04 15:00:51.928 I/MonoDroid(30757): at System.Security.Cryptography.SHA1+Implementation.HashFinal + 0x0(Unknown Source)
02-04 15:00:51.928 I/MonoDroid(30757): at System.Security.Cryptography.HashAlgorithm.CaptureHashCodeAndReinitialize + 0x0(Unknown Source)
02-04 15:00:51.928 I/MonoDroid(30757): at System.Security.Cryptography.HashAlgorithm.ComputeHash + 0x22(Unknown Source)
02-04 15:00:51.928 I/MonoDroid(30757): at Sentry.Internal.Extensions.HashExtensions.GetHashString + 0x11(Unknown Source)
Activity