Strong naming an assembly uses public/private key cryptography. So this involves two keys that are mathematically related but not derivable from eachother. Anything encrypted with one can be decrypted with the other. The idea is that one of these keys is in the public domain, the other you keep secret (the private one). When two people generate a key pair (using the strong name utility sn.exe) the key pairs they generate will be different - including the public keys.
When you sign an assembly with a key pair thet compiler put the public key oin the assembly manifest - this gives the assembly a unique name. It also calculates a hash of the file (using the algorithm that will be identified by the HashAlgortihm entry in the assembly manifest) and encrypts this with the private key. This encrypted signature is stored in the assembly as well.
When you build against a string named assembly, a hash of the public key of that assembly (the PublicKeyToken) is put in the applications manifest in an external assembly reference. Now when the app;ication runs, at some point the JIT compiler compiles a type in that assembly. When it does so it needs to locate the assembly that houses the type and so the Assembly Resolver kicks in. This pushes the assembly name and configuration information to specifiy a physical localtion from which to load the assembly.
The Assembly Loader then loads the assembly. It notices that it has a strong name - the public key is in the manifest remember. So it decrypts the signature with the public key and rehashes the assembly if the decrypted hash and the one just calculated match then the assembly hasn't been tampered with, if they differ then it does.
One caveat: the above description does not take account of various other things that may have been done to try to get around this mechanism which we can discuss if you want to go deeper.
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
Hello sirs,
I am trying to understand how strong names work.
Suppose I have lib.dll (a .net library), and also MyApplication.exe (a .NET
WinApp) . MyApplication uses lib.dll . Suppose someone decompiles lib.dll
and replaces code parts, and then recompiles again. When MyApplication.exe
will load lib.dll the next time, will it detect that it is a different dll
if they have strong names?
How can I implement this procedure? If someone can give me an example I
would appreciate!
Thanks a lot!