Reputation: 6026
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).
Upvotes: 2
Views: 2697
Reputation: 43553
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).
Upvotes: 2