tags:

views:

115

answers:

1

How can I find a .NET assembly's public key via code?

From the command line, I can use sn -Tp assemblyName to find the public key.

What's the equivalent (c# or VB) in code?

+3  A: 

You want to use the AssemblyName.GetPublicKey() method.

using System;
using System.Reflection;

class Program
{
    static void Main()
    {
     Byte[] key = Assembly.GetExecutingAssembly().GetName().GetPublicKey();

     foreach (Byte b in key)
      Console.Write("{0:x}", b);
    }
}
Andrew Hare