When you put an assembly into GAC (Global Assembly Cache), you must enhance the name (signature ), the Assembly in GAC can be referenced and accessed by all programs (equivalent to the previous COM component registration in the registry, this Assembly (private assembly) needs to be copied when using this Assembly. Therefore, you do not need to use a strong name, depending on the situation.
If you do not want to share. dll, you can use a strong name.
A strong name is used to ensure the security of your DLL files. Generally, we can use a DLL file wherever it is referenced.
However, if a strong name is used, the DLL will have a key, and others will not be able to reference it.
How to create an assembly with a strong name
You can assign an encrypted signature called a strong name to an assembly. It provides the Assembly with unique names and prevents others from using your Assembly name (name spoofing ). If you are deploying an assembly that will be shared by multiple applications on the same computer, the Assembly must have a strong name. Even if you only use the Assembly in your application, use a strong name to ensure that the correct version of the Assembly is loaded.
The first step to generate an assembly with a strong name is to obtain an encryption key pair .. Net Framework SDK includes a "Strong name" tool (sn.exe) that can be used to generate key pairs ). Key pairs generated by the "Strong name" tool can be stored in files, or you can store them in the "encryption service provider" (CSP) on your local computer. The following command uses the "Strong name" tool to generate a new key pair and store it in a file named testkey. SNK:
Sn-K testkey. SNK
After obtaining the key pair, you must add the correct custom attributes to the source file so that the compiler can issue an assembly with a strong name. Select the attribute correctly based on whether the key pair used for signature is included in the file or the key container in the CSP. For keys stored in files, use system. reflection. assemblykeyfileattribute. For keys stored in CSP, use system. reflection. assemblykeynameattribute.
(*) If no key is specified, the Assembly will not be signed.
// (*) Keyname indicates that it has been installed on
// The key in the computer's encryption service provider (CSP. Keyfile refers to include
// Key file.
// (*) If both the Keyfile and keyname values are specified
// The following process occurs:
// (1) if the keyname can be found in CSP, use this key.
// (2) if the keyname does not exist and the Keyfile exists
// Install the key in the Keyfile into the CSP and use the key.
// (*) To create a Keyfile, you can use the sn.exe (strong name) utility.
// When Keyfile is specified, the Keyfile location should be
// Compare to "project output directory ". Project output
// The directory location depends on whether you are using a local project or a Web project.
// For local projects, the project output directory is defined
// <Project directory> \ OBJ \ <configuration>. For example, if the Keyfile is in
// In the project directory, set assemblykeyfile
// Specify the attribute as [Assembly: assemblykeyfile (".. \ mykey. SNK")]
// For a web project, the project output directory is defined
// % Homepath % \ vswebcache \ <machine Name> \ <project directory> \ OBJ \ <configuration>.
It can be used as the key of the. dll file during compilation. If you use another *. SNK file to replace the original file,. dll cannot be compiled.