android.runtime.JavaProxyThrowable: [System.Security.Cryptography.CryptographicException]: Cryptography_ConcurrentUseNotSupported
- Dominant language
- C#
- Stars
- 2.1k
- Forks
- 579
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 257
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
1. Create a blank .net9.0 android application
2. Add msbuild property:
```xml
false
```
3. Add the following code:
```csharp using var sha = SHA1.Create(); // can be SHA2, SHA256, etc
var hash = sha.ComputeHash(bytes); // will die here
var hi = Convert.ToHexString(hash);
Console.WriteLine("SAMPLE HASH: " + hi);
```
4. Run in release mode
5. 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
```csharp
#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
```shell
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)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.