StrongKey in Assembly using C#

In this article we will discuss about how to make the strong key for Assembly in C#.
  • 2849

To build public and private keys we have to use the sn (short for strong name) utility. This utility generates a public/private key pair. The public key created using this utility will be used to define a strong name. To create the key pair we must type the following at command prompt:

The steps are as follows:

  1. Open the Visual Studio 2010.
  2. Then go to Visual Studio Tools.
  3. Then go to Visual Studio Command Prompt(2010).
  4. A Command prompt will open and write the following command to make the strong key file.

    10.jpg

On executing the utility a file called mykey.snk gets created. The files contains the public and private keys. To create a strong name, the compiler uses the public key from mykey.snk file, hence we must provide this file to the compiler.

To see the location of the strong key file just go to the D: drive and mykey strong key file will be created. We can select the location as per our requirement.

              11.jpg

Now we will assign the strong key to our assembly to make its name unique. The steps are as follows:

  1. Just go to location where you have make the dll.
  2. Then right click on the project folder and select the property option.
  3. Then choose the Signing option from the left hand sides option.
  4. Then check the checkbox of the sign the assembly.
  5. Then choose a strong key name from the dropdownlist just select the browse option from it and select the location of the strong key file.

    12.jpg

In this way we will assign the strong key to our assembly then rebuild your dll to make changes. The strong key name make the assembly unique.

Ask Your Question 
 
Got a programming related question? You may want to post your question here
 
© 2019 DotNetHeaven. All rights reserved.