RSACryptoServiceProviderProxy crashes on Mono
See original GitHub issueSystem.Security.Cryptography.CryptographicException: Keyset does not exist
at System.Security.Cryptography.RSACryptoServiceProvider.Common (System.Security.Cryptography.CspParameters p) [0x00000] in <filename unknown>:0
at System.Security.Cryptography.RSACryptoServiceProvider..ctor (Int32 dwKeySize, System.Security.Cryptography.CspParameters parameters) [0x00000] in <filename unknown>:0
at System.Security.Cryptography.RSACryptoServiceProvider..ctor (System.Security.Cryptography.CspParameters parameters) [0x00000] in <filename unknown>:0
at System.IdentityModel.Tokens.RSACryptoServiceProviderProxy..ctor (System.Security.Cryptography.RSACryptoServiceProvider rsa) [0x00000] in <filename unknown>:0
at System.IdentityModel.Tokens.AsymmetricSignatureProvider..ctor (System.IdentityModel.Tokens.AsymmetricSecurityKey key, System.String algorithm, Boolean willCreateSignatures) [0x00000] in <filename unknown>:0
at System.IdentityModel.Tokens.SignatureProviderFactory.CreateProvider (System.IdentityModel.Tokens.SecurityKey key, System.String algorithm, Boolean willCreateSignatures) [0x00000] in <filename unknown>:0
at System.IdentityModel.Tokens.SignatureProviderFactory.CreateForSigning (System.IdentityModel.Tokens.SecurityKey key, System.String algorithm) [0x00000] in <filename unknown>:0
at System.IdentityModel.Tokens.JwtSecurityTokenHandler.CreateSignature (System.String inputString, System.IdentityModel.Tokens.SecurityKey key, System.String algorithm, System.IdentityModel.Tokens.SignatureProvider signatureProvider) [0x00000] in <filename unknown>:0
at System.IdentityModel.Tokens.JwtSecurityTokenHandler.CreateToken (System.String issuer, System.String audience, System.Security.Claims.ClaimsIdentity subject, Nullable`1 notBefore, Nullable`1 expires, System.IdentityModel.Tokens.SigningCredentials signingCredentials, System.IdentityModel.Tokens.SignatureProvider signatureProvider) [0x00000] in <filename unknown>:0
at AspNet.Security.OpenIdConnect.Server.OpenIdConnectServerHandler+<CreateIdentityTokenAsync>d__21.MoveNext () [0x00000] in <filename unknown>:0
Mono doesn’t use CryptoAPI - which is Windows-specific - and always initializes CspKeyContainerInfo.ProviderType
to 1
, which causes RSACryptoServiceProviderProxy
to create a proxy around the existing RSA provider. Sadly, it crashes on Mono.
The bug disappears when you remove csp.Flags |= CspProviderFlags.UseExistingKey;
from RSACryptoServiceProviderProxy
’s constructor.
Issue Analytics
- State:
- Created 8 years ago
- Comments:45 (28 by maintainers)
Top Results From Across the Web
Mono 4.8.0 Release Notes
Mono now ships with TLS 1.2, powered by Google's BoringSSL project. ... 3434: Mono Compiler crashes when using a DelegateType as a method ......
Read more >Bug in Mono !? WebRequest to a HTTPS resource with ...
I have a proxy(Fiddler) setup and I created an Android app on Windows 10 x64 with latest Xamarin stable as of today, with...
Read more >Mono 4.8.0
Release 4.8.0 of Mono, released on 2017-02-22. versionsof.net gives an ... 3434: Mono Compiler crashes when using a DelegateType as a method ...
Read more >mono-runtime-common — Debian stretch
mono is a runtime implementation of the ECMA Common Language Infrastructure. ... This mode should not allow managed code to crash mono.
Read more >Untitled
#Rsacryptoserviceprovider Fu rin ka zan remix song, Best french books to read ... Redirect external proxy di mikrotik download, Tangerine dream love on...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@andycmaj that’s another bug: https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/477
@in10se Sorry it took so long. My solution is actually pretty wildly stitched together. The idea is that the
SignatureProvider
actually creates (or, back then, created) anRsaCryptoServiceProviderProxy
to manage the signing and verification of RSA keys, which failed on mono. So I first wrote aCustomRsaCryptoServiceProviderProxy
which would be instantiated by aCustomAsymmetricSignatureProvider
instead, but in the end just skipped that part altogether by having that class’ constructor callThe
CustomAsymmetricSignatureProvider
would be implictly used in theJwtSecurityTokenHandler
’sCreateJwtSecurityToken
method asand in the
Startup
asNote that
CryptoProviderFactory.Default
currently doesn’t seem to have any effect.