Question

I have a problem with extraction of public key from PFX file. First thing which i have used is X509Certificate2. However public key received in this way is encrypted, and i want to have this key to be compatible with InternalsVisibleTo Attribute - In Examples section there is an sample of such key. Is there a way to extract this key in compatible form (Compatible to InternalsVisibleTo).

Was it helpful?

Solution

It's simply a formatting issue, i.e. X509Certificate2 should return you the decrypted public key (or fail, e.g. bad password).

I suggest you to follow what Mono does to strong name assemblies, i.e. its own sn tool. While Mono's sn.exe does not directly read PKCS#12 files it can read from key containers, so you end up with a RSACryptoServiceProvider in both case.

Just drill down into the source code, it's all C# and not very long, and you'll find what you need there (or in one of the few helper classes that are involved).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top