Sunday, May 23, 2010

Difference PublicKey vs PublicKeyToken

Hi Friends,

We all have seen the PublicKeyToken in the web.config file. Most of the begineers will assum that "When we sign the assambly, it will have PublicKeyToken for the signed it. And the PublicKeyToken is the public key for the assambly." Well this is not true.

We all know that we can sign an assambly with .snk file. For those who don't know how to generate a sign key, you can generate a new key with sn.exe tool shipped with Visual Studio.

Now the .snk file contains PublicKey and a PrivateKey for the assambly to encrypt/decrypt the data.
Now the actual PublicKey is a 128 byte opaque algorithm specific structure. It also have extra 32 byte data for headers.

Now the question is, if PublicKey is 128 + 32 bytes then why we write only 16 characters for PublicKeuToken in web.config. What is the difference between PublicKey and PubilcKeyToken.
PublicKeyToken is a 8 byte hash for the full PublicKey.

Most of compilers use this token instead of full PublicKey to keep the assembly's manifest smaller.

Hope this information will be helpful to all.



  1. Nice comparison..... i like such comparisons..
    Thank you for sharing...Joomla Toronto

    1. Yes really its very informative and i agree with LC David who appreciate this post.

  2. Public key is the hash of the strongly-named assembly's and these hashes are generally known as public key tokens, they are the low 8 bytes of the hash of public keys(128 bytes).


Comments posted on ASP.Net Ajax Tutorials Blog are moderated and will be approved only if they are on-topic and not abusive. Please email me or my team for tech-support or blogging related questions. Avoid including website URLs in your comments - Thanks Author