This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Visual Studio
VS 2005+

Signing an Assembly in Visual Studio

To protect your assemblies from unauthorised changes you should sign them using a strong name key. This process uses public and private cryptographic key technologies that can prove the origin and the integrity of your software to the end user.

Signed Assemblies

All .NET assemblies can optionally be signed using a combination of public and private cryptographic keys. When signed, the name, version number and other assembly details are encoded using the keys to generate a hash value or cryptographic digest. When a signed assembly is loaded on the end user's system, the validity of the digest is checked using a similar process. If the assembly has been modified the integrity of the software is in question and the application will not run.

The signing process protects the end user from the unauthorised changes to assemblies that can occur due to virus infection or from the effects caused by other types of malware. It also guarantees the source of the application and ensures that the correct assembly versions are used.

Although signing is generally optional, there is no drawback to adding this level of protection. In some situations, your assemblies must be signed. For example, it is not possible to add an unsigned assembly to the global assembly cache (GAC) or to use it as a plug-in or extension to some applications, such as Microsoft Dynamics CRM.

Strong Name Key Files

When signing an assembly, a strong name key file is required. This file contains the pair of keys (public and private) that will be used to generate the cryptographic digest for the assembly. Prior to Visual Studio 2005, the key file was created using the strong name tool. This is a command-line tool, named "sn.exe", that is installed as part of the .NET framework. In Visual Studio 2005 and 2008, the file can be created and associated with a project directly within the development environment.

Strong name key files can be used for any number of assemblies. Depending upon your organisation's policies, you may use a single key file for all software, a new key file for each application or even a different key file for every assembly. Any of these options is a valid approach. In any case, the key files should be carefully protected. If the keys are made available to malicious users, this can give the opportunity for inappropriate use.

Signing an Assembly

To sign an assembly from within Visual Studio, you simply mark the assembly as signed and provide a key file. This is achieved using the project's properties. To view the properties, select the project that contains the code for the assembly that you wish to sign using the solution explorer. You can then either select the Properties option from the Project menu or right-click the project name in the solution explorer and choose Properties. Within the window that appears, select the Signing tab as shown below.

Visual Studio Signing Options

To specify that the assembly is to be signed, tick the "Sign the assembly" checkbox. If you already have a strong name key file, select the "<Browse...>" option from the drop-down list and choose the key file from the file system.

If you wish to create a new strong name key file for the assembly, select "<New...>" from the drop-down list. The Create Strong Name Key dialog box will be displayed. Here you can specify a name for the key file and, if required, a password to protect the file.

Create Strong Name Key Dialog Box

When you have specified the details for the new file, click OK. The new key file will be added to the project. The file will be named with the name that you supplied and an extension of ".snk" for unprotected files or ".pfx" for password-protected files. When you next compile the project, the generated assembly will be signed.

4 September 2008