Reading the public key inside a strongly signed assembly from the assembly itself???

B

Bob Rock

Hello,

is it possible to programmatically read (and how) the public key that is
embedded into an assembly that has been strongly signed???
What code would be needed???

Bob Rock
 
N

Nicole Calinoiu

Bob,

The method below returns the key (if one is found) from any type's assembly.
To use it to retrieve the current assembly's key, call it as follows
(assuming you're calling from the class in which the method is declared):

StrongNamePublicKeyBlob myKey = this.GetSigningKey(this.GetType());

HTH,
Nicole


public StrongNamePublicKeyBlob GetSigningKey(Type sourceType)
{
if (sourceType == null) throw new ArgumentNullException("sourceType");

StrongNamePublicKeyBlob retVal = null;

foreach (object test in sourceType.Assembly.Evidence)
{
if (test is StrongName)
{
retVal = ((StrongName)test).PublicKey;
break;
}
}

return retVal;
}
 
M

Michel Gallant

AssemblyName assemname = Assembly.LoadFrom(<assemblyfile>).GetName() ;
byte[] pubkey = assemname.GetPublicKey() ;

- Mitch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top