Bug 5299 - RSACryptoServiceProvider.ExportCspBlob() returns different result
Summary: RSACryptoServiceProvider.ExportCspBlob() returns different result
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 2.10.x
Hardware: PC Windows
: --- minor
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2012-05-24 03:56 UTC by Jeroen Frijters
Modified: 2012-05-30 14:32 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

repro (4.17 KB, text/plain)
2012-05-24 03:56 UTC, Jeroen Frijters

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jeroen Frijters 2012-05-24 03:56:55 UTC
Created attachment 1948 [details]

When the attached program is run on Mono the results differ from .NET (in particular the sixth byte is 0xA4 on Mono and 0x24 on the CLR.

This difference showed up because IKVM.Reflection now uses this method to extract the public key from a key pair and this caused an mcs test failure.
Comment 1 Sebastien Pouliot 2012-05-24 08:18:46 UTC
0x24 means CALG_RSA_SIGN, i.e. an RSA key used for signature
0x42 means CALG_RSA_KEYX, i.e. an RSA key used for key exchange

CryptoAPI makes a difference about them, even if it's often only for storage (two key pairs per containers) but it really depends on the CSP implementation (hardware CSP are generally more restrictive). 

However .NET does not differentiate them and by default returns 0x42 (for new keys). That will differ if you roundtrip a key from a CAPIBLOB because the key gets stored into CryptoAPI (using the original value).

Mono does not use CryptoAPI and it's keystore store do not support features that are not required for other parts of the framework (and that includes this bit of information). There's a few ways to solve this (some simpler than others) but I need to know which mcs test is failing ? (if only to determine the existing key check is valid).
Comment 2 Jeroen Frijters 2012-05-24 08:34:21 UTC
If it helps, the scenario is exactly like the repro, ImportCspBlob followed by ExportCspBlob. This is just a way to extract the public key.
Comment 4 Sebastien Pouliot 2012-05-30 14:32:54 UTC
Fixed in master