Trusted pfx cert not working with InternalsVisibleTo attribute

335 Views Asked by At

I got a trusted cert from Comodo CA and having a hard time getting it to work with the InternalsVisibleTo Attribute. I'm getting a warning that the assembly is invalid and can't be resolved. I retrieved the public Key with X509Certificate.GetPublicKeyString() and put that into the assemblyinfo.

[assembly:System.Runtime.CompilerServices.InternalsVisibleTo("Assemblyname,PublicKey=MyPublicKey"]

We had used an untrusted cert so far and it works fine with it. What I noticed is that the PublicKey of the trusted cert (.pfx) is 540 characters long and our untrusted (.snk) is just 320.

Where is my error?

Additionally I can't use the projectsettings to pick my .pfx to sign it. Postbuild works. when using the projectsettings it tells me that it cant find the cert and the private key.

1

There are 1 best solutions below

6
Evk On BEST ANSWER

It's hard to tell what is the problem without trying to do the same myself. Maybe the format of public key returned by X509Certificate.GetPublicKeyString() is not the format InternalsVisibleTo expects. However, you can use sn (Strong Name Tool), which was designed just to work with strong name keys.

It's located at C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin (number of SDK\ system drive etc may vary, but you get the idea).

First export public key using this command (will ask for password if pfx is password-protected):

sn -p YourComodoCert.pfx YourComodoCert.snk

Then export public key as a string via:

sn -tp YourComodoCert.snk > YourComodoCert_pub.txt

Open YourComodoCert_pub.txt with text editor, there you will found "Public key is" section - copy key from there and use in InternalsVisibleTo.