Determine if assembly has a strong name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm loading an assembly from disk (Assembly.LoadFrom) and would like to find
some way of determining if the assembly was signed. Ideally I would then
like to be able to compare a key file with the assembly and find out if the
given key was the one it was signed with.

Thanks in advance,
Mike
 
I saw your post earlier today, but didn't have anything for you. but
while snooping arround, I found the AssemblyName.Flags and
AssemblyName.KeyPair properties. You can probably use them, but that
would be after you'd already loaded it. You're probably looking to verify
the assembly before loading. You have to do that with security Evidence
parameter.

Sorry I can't be more helpful.
 
You can probably use them, but that
would be after you'd already loaded it. You're probably looking to verify
the assembly before loading. You have to do that with security Evidence
parameter.

You can get the AssemblyName without loading the assembly with
AssemblyName.GetAssemblyName().



Mattias
 
Hi Mike,

I think Mattias's suggestion on using the "AssemblyName" class is quite
good. The AssemblyName class has a "GetPublicKeyToken" method you can use
it to check whether the assembly has a signed key token or not. For
example:

AssemblyName an = null;

an = AssemblyName.GetAssemblyName(AppDomain.CurrentDomain.BaseDirectory +
"\\" + "SNLib.dll");
Console.WriteLine("AssemblyName.Name: " + an.Name);
Console.WriteLine("AssemblyName.FullName: " + an.FullName);
Console.WriteLine("AssemblyName has PublicKeyToken: " +
(an.GetPublicKeyToken() != null));

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top