I know that it is done by signing assembly with private key.
So here how I see the process …
When we have the private/public key pair file we can build assembly signing it using this keys.
So what in reallity is done is that compiler opens the ‘sk'(or pfx) file and retreives the private key (which I understand is impossible for human) and after signing the assembly with the private key it adds the public key into assembly manifest and that is it I have the strongly named assembly.
So what when I run the application which is referencing that assemly ?
What does CLR to be sure that the assebly is not replaced and nothing was changed?
A quote from CLR via C#
Well, here how it works.
When you compile the assembly noting that you want to sign it with already generated public/private key pair file the compiler computes the hash of the assembly (also computes hashes for each file in the assembly and stores the values along with file names in FileDef table) then it signs the hash value with private key and embeds public key in manifest for that assembly.
Now in runtime when the application (assembly) tries to load that signed assembly the assembly is again hashed then CLR gets the public key from the assembly manifest and decrypts the RSA sign and compares the hash value with the sign value. If they are the same than nothing was changed.