to sign an assembly with a strong name, you must have a public/private key pair. This pair of cryptographic public keys and cryptographic private keys are used to create strong-named assemblies during compilation. You can use the Strong Name tool (Sn.exe) to create a key pair. A key pair file typically has an. snk extension.
Attention |
In Visual Studio, the C # and Visual Basic project property pages include a"Signature"tab, this tab allows you to select an existing key file or generate a Xinmi key file without using Sn.exe.In Visual C + +, you can specify the location of an existing key file in the Advanced property page in the linker section of the Configuration Properties section of the Property Pages window. starting with Visual Studio 2005, using the AssemblyKeyFileAttribute attribute to identify the use of key file pairs is obsolete. |
create a key pair
At the command prompt, type the following command:
sn–k <file name>
In this command, "file name" is the name of the output file that contains the key pair.
The following example creates a key pair named Sgkey.snk.
Sn-k sgkey.snk
If you need to delay signing the assembly and control the entire key pair (the key pair is unlikely to be outside the test scenario), use the following command to generate the key pair, and then extract the public key into a separate file. first, create a key pair:
Sn-k keypair.snk
Sn-p keypair.snk Public.snk
assembly Linker (Al.exe) looks for the key file Relative to the current directory and to the output directory. " > when signing an assembly with a strong name, the Assembly Linker (Al.exe) finds the key file associated with the current directory and output directory. When using the command-line compiler, simply copy the key to the current directory containing the code module.
If you are using an earlier version of Visual Studio and there is no signature tab in the project properties, the recommended key file location is the project directory with the file attributes specified as follows:
C#c++vb
[Assembly:assemblykeyfileattribute ("Keyfile.snk")]
Please see
Creating and using strong-named assemblies
How to: Create a public/private key pair