PublicKeyToken generation.

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

Guest

For a remoting application I need to specify in the configuration the full
name of the assembly because the remoting object is in the GAC so I need to
specify the version and the public key token. Both the version and the public
key token is the same as the calling assembly so I just need to get these
values to specify a full assembly name. The version is no problem. I am
having some problem with the PublicKeyToken. From the Assembly class I can
retrieve the AssemblyName class which has a property KeyPair which also has a
property PublicKey My question is, what do I need to do to generate the
PublicKeyToken from the PublicKey?

Thank you

Kevin
 
Kevin,
My question is, what do I need to do to generate the
PublicKeyToken from the PublicKey?

AssemblyName.GetPublicKeyToken() returns an array with just the token
bytes. You can then format it as a hex string.



Mattias
 
Thank you. I overlooked that method. The next question is really an FAQ but
how is the best way to generate a hex string given a byte array?
 
Kevin,

Are you really just trying to figure out what the public key token is
for an assembly loaded into the GAC? If that's all your trying to do,
there is a simpler way. Using Windows Explorer, explore to the GAC
directory on the PC, which should be "c:\WINDOWS\assembly". One of the
properties of all assemblies in the GAC is the public key token. You
should be able to see the public key token by either right-clicking the
assembly and looking at properties, or by scrolling to the right-hand
edge of the GAC folder's view.

HTH,

--steve
 
It is a little more complicated than that. We use a single public/private key
to sign all of our assemblies. So, if I get the PublicKeyToken for one
assembly I know it for all assemblies. In a service I am setting up
(configuring) a call to a remote server using a remoting object. Since that
object is in the GAC (on the remote server) I need to specify the full name
including the PublicKeyToken. I could hard-code the PublicKeyToken but I
thought a better way would be to get the PublicKeyToken from the executing
assembly and use that to configure the remoting object. That is where this
all started from.

Kevin
 
Kevin,
Thank you. I overlooked that method. The next question is really an FAQ but
how is the best way to generate a hex string given a byte array?

Something like this for example

StringBuilder buffer = new StringBuilder(16);
foreach ( byte b in assemblyName.GetPublicKeyToken() )
buffer.AppendFormat( "x2", b );
string keyToken = buffer.ToString();



Mattias
 
Back
Top