I have findout few other links that are described in good way about "How to generate Strong Name Keys snk? How to set reference snk in application? How to istall dll in assembly folder GAC ". I hope this is very helpful for developers. Related Content ASP. NET Globalization Localization. NET VB. NET Interview. You can strong-name assemblies by using Visual Studio or a command-line tool. For more information, see How to: Sign an assembly with a strong name or Sn.
When a strong-named assembly is created, it contains the simple text name of the assembly, the version number, optional culture information, a digital signature, and the public key that corresponds to the private key used for signing.
You want to enable your assemblies to be referenced by strong-named assemblies, or you want to give friend access to your assemblies from other strong-named assemblies. An app needs access to different versions of the same assembly. This means you need different versions of an assembly to load side by side in the same app domain without conflict. For example, if different extensions of an API exist in assemblies that have the same simple name, strong-naming provides a unique identity for each version of the assembly.
You do not want to negatively affect performance of apps using your assembly, so you want the assembly to be domain neutral. This requires strong-naming because a domain-neutral assembly must be installed in the global assembly cache. You want to centralize servicing for your app by applying publisher policy, which means the assembly must be installed in the global assembly cache. NET Core and.
This command also displays the public key token marked in bold , which is a hash code of the public key, used by other assemblies as a compact way of referencing your public key. You can install the newly created key pair into the Windows Cryptographic Service Provider CSP container, which provides a centralized store of key pairs. Installing key pairs in the CSP offers easier administration than storing the keys in a disk file; see the Windows documentation for full details.
The following command demonstrates how to install keys into a CSP container called MyCSPContainer ; you will see how to use this container in the following sections. It is very important that your private key remains a secretif not, then assemblies can be assigned strong names, which will appear to have originated from you. And why be granted an unwarranted level of trust by system administrators?
Before you can generate a strong name, you need to specify the assembly's version and culture metadata; remember that a strong name consists of the assembly name, the version and culture information, plus a public key and a digital signature.
The simplest way to specify the version and culture metadata is to use the System. AssemblyVersion and System. AssemblyCulture attributes, applied at the assembly level. Visual Studio. NET creates a file called AssemblyInfo. NET as part of a project; this file contains attributes for all of the configurable assembly metadata.
We shall follow this convention to specify the metadata for our example assembly from Section 2. NET documentation for details of version and culture configuration :. We specify the key pair to use when creating the strong name by adding an attribute that refers to either the file or CSP container that contains our key pair; we do this with the AssemblyKeyFile and AssemblyKeyName attributes.
You should specify a file or a CSP containerdo not specify both. To specify a key pair file, add the following attribute to the AssemblyInfo. NET language compilers will automatically create the strong name if you specify AssemblyInfo. The following command demonstrates how to apply the strong name to the example single-file assembly that you created previously:.
For a single-file assembly, the compiler uses the assembly attributes to locate the key pair and generates the strong name. When working with a multifile assembly, you must specify the information required for the strong name as arguments to the Assembly Linker tool al. The examples in the previous sections assume that you are able to either create or access the key pair used to create strong names.
In large organizations, a signing authority may manage the key pair, and you are required to submit your assemblies for signing; this is especially likely if a single key pair is used to create strong names for the assemblies produced by more then one project. NET Framework supports delayed signing , where the public key is included in the assembly, but the signature is not created; this allows you to compile and test your assemblies without requiring access to the secret private key.
The first step is to obtain the public key from the key pair, a task usually performed by the signing authority; the following command demonstrates how to extract the public key from the key file and place it in a file called MyPublicKey. For a single-file assembly, enable delayed signing with the AssemblyDelaySign attribute, which you add to the AssemblyInfo. The assemblies that these commands create do not have strong names, because they are not digitally signed.
The signing authority can subsequently complete the strong name by using the - R argument of the Strong Name tool, as follows:. This technique applies to single- and multifile assemblies.
As well as specifying the name of the assembly to sign, you must provide the name of the key file that contains the public and private keysthe public key file cannot be used to create a digital signature.
You can specify a CSP container from which to obtain the key pair with the - Rc argument, as follows:. You can verify an assembly strong name with the Strong Name tool sn.
The following command verifies our example single-file assembly:. You can also determine the public key from the key pair used to create the digital signature using the following command:.
The result of this command is shown below, and you can see that this matches the public key we created in Section 2. Toggle navigation. See also. Home Programming. NET Programming security. Two properties of digital signatures support this position: Digital signatures are associated with a hash code generated from the contents of the assembly; this hash code acts as a "fingerprint" for the assembly contents, and it is very difficult to find two assemblies with the same fingerprint.
0コメント