How to: Create a public/private key pair

Source: Internet
Author: User

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
    1. 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
    • Next, extract the public key from the key pair and copy it into a separate file:

Sn-p keypair.snk Public.snk
    • After you create a key pair, you must place the file in a location that the strong name signing tool can find.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.