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

  • Thread starter Thread starter Bob Rock
  • Start date Start date
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
 
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;
}
 
AssemblyName assemname = Assembly.LoadFrom(<assemblyfile>).GetName() ;
byte[] pubkey = assemname.GetPublicKey() ;

- Mitch
 
Back
Top