Skip to content

android.runtime.JavaProxyThrowable: [System.Security.Cryptography.CryptographicException]: Cryptography_ConcurrentUseNotSupported #9752

Open
@aritchie

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:
<AndroidEnableAssemblyCompression>false</AndroidEnableAssemblyCompression>
  1. Add the following code:
  var hash = sha.ComputeHash(bytes); // will die here
  var hi = Convert.ToHexString(hash);
  Console.WriteLine("SAMPLE HASH: " + hi);
  1. Run in release mode
  2. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Area: App RuntimeIssues in `libmonodroid.so`.need-attentionA xamarin-android contributor needs to review

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions