Hex String to byte array conversion

This is a discussion on Hex String to byte array conversion within the C# Programming forums, part of the General Programming Boards category; OK...so what I'm really trying to do is use the Assembly.Load function to dynamically load an assembly, that is in ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446

    Hex String to byte array conversion

    OK...so what I'm really trying to do is use the Assembly.Load function to dynamically load an assembly, that is in the GAC (and not part of my local project). My research indicates that to do this, I need to give the Load function an AssemblyName object that has the .Name, .Version, and public key specified. So for a test, I tried to load System assembly dynamically.

    This is the info I came up with when I looked in the GAC:

    Name: System
    Version: 7.0.5000.0
    Public key: b77a5c561934e089

    Ok so the name and Version is no problem, but the AssemblyName.SetPublicKey function expects a Byte array as input.

    So this is where I'm at, trying to figure out how to convert the string "b77a5c561934e089" into a suitable byte array. I have a feeling that somewhere in the framwork there exists a function that does all the work on this, but I can't seem to find it. Any help would be appreciated.
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  2. #2
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    Ok...an update. So the hex number I provided above is not really the public key, it's the Public Key Token, which is apparently different than the public key. Now I'm left wondering, how do I get the public key for an assembly such as System.dll?
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  3. #3
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Code:
    Assembly asm = 
    	Assembly.Load("system, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
    Replace with your own particular System.dll information.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  4. #4
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    Damn, That was easy, thanks.
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 03:45 PM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 02:02 AM
  3. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 09:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21