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

Discussion in 'ASP .Net Security' started by Bob Rock, May 16, 2004.

  1. Bob Rock

    Bob Rock Guest

    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 Rock, May 16, 2004
    #1
    1. Advertising

  2. 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;
    }

    "Bob Rock" <> wrote in message
    news:...
    > 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
    >
    >
    Nicole Calinoiu, May 16, 2004
    #2
    1. Advertising

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

    - Mitch

    "Bob Rock" <> wrote in message
    news:...
    > 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
    >
    >
    Michel Gallant, May 16, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Prasanna Padmanabhan
    Replies:
    1
    Views:
    799
    Mattias Sjögren
    Nov 19, 2003
  2. Charles A. Lackman
    Replies:
    1
    Views:
    1,320
    smith
    Dec 8, 2004
  3. =?Utf-8?B?UGF1bA==?=
    Replies:
    3
    Views:
    374
    =?Utf-8?B?UGF1bA==?=
    Oct 14, 2005
  4. Replies:
    0
    Views:
    655
  5. Sean O'Day
    Replies:
    0
    Views:
    133
    Sean O'Day
    Jul 21, 2003
Loading...

Share This Page