dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.29k stars 4.74k forks source link

RSACryptoServiceProvider.ExportParameters hangs on BWA #36806

Closed rkttu closed 4 years ago

rkttu commented 4 years ago

Describe the bug

I tested a code which relies on RSACryptoServiceProvider.ExportParameters function in Blazor WebAssembly, but it hangs after the function called.

To Reproduce

I tested the below code in the SDK 3.1.300 (3.1.4 release).

private RSACryptoServiceProvider csp;
...
this.csp = new RSACryptoServiceProvider(keySize);
...
var parameters = csp.ExportParameters(true); // This line causes hang.
var parameters = csp.ExportParameters(false); // This line also causes hang.

Further technical details

.NET Core SDK(global.json 반영):
 Version:   3.1.300
 Commit:    b2475c1295

런타임 환경:
 OS Name:     Windows
 OS Version:  10.0.19041
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.300\

Host (useful for support):
  Version: 3.1.4
  Commit:  0c2e69caa6

.NET Core SDKs installed:
  2.1.607 [C:\Program Files\dotnet\sdk]
  3.1.300 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
ghost commented 4 years ago

Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq Notify danmosemsft if you want to be subscribed.

davidfowl commented 4 years ago

Likely a mono issue?

shawnshaddock commented 4 years ago

I'm having an issue with ExportParameters(true) as well. It takes an extremely long time to return, and when it finally does return the private parameters aren't there. Only Exponent and Modulus are populated.

mdh1418 commented 4 years ago

Blazor WebAssembly in .NET 5 does not support cryptography libraries. It will throw System.PlatformNotSupportedException: System.Security.Cryptography is not supported on Browser.

rkttu commented 4 years ago

@davidfowl @mdh1418 Thanks for your comment. I understand that local cryptography in Blazor is a corner and rare use case. Also, it requires lots of computing resources. But I didn't find any notice or best practices about cryptographic API that does not support Blazor. This situation makes some confusion. If possible, even in the current version, this API should also throw the exception to prevent further trouble.

rkttu commented 4 years ago

For those of you interested in this topic, there is one piece of information I found. I found an alternative implementation. It will be an alternative implementation of built-in local cryptography.

https://github.com/ebekker/FMRL/tree/master/BlazorX.WebCrypto

https://github.com/BlazorExtensions/Home/issues/1