Creating Strong Named Assemblies in Microsoft .Net
Strong Names are a way of uniquely identifying assemblies written for the .Net platform. They are not, as commonly believed, a tool for enabling security.
- Getting Started with Visual Studio
- Using the Visual Studio Integrated Development Environment
- Using the Visual Studio Debugger
- XML Documentation in Visual Studio
- Using Microsoft .Net Command Line Tools
- What is an Assembly in Microsoft .Net?
- Creating and Using a .NET Assembly in C#
- Creating and Implementing Satellite Assemblies
- Creating Strong Named Assemblies in Microsoft .Net
- Visual Studio Task List
- Resources and Localisation in C# Projects
- Localising Microsoft .Net Applications with C#
- Using Resource Files in C# Applications
- Using XSD Tool to Generate Classes from XML
- 10 Visual Studio Tools You May Not Know About
Adverts Blocked Please disable AdBlocking software and allow me to set cookies so that I can continue providing free content and services.
Strong Names use cryptographic techniques (RSA, El Gamal etc...) together with a hashing algorithm (Md5, SHA, Blowfish etc...) to create a digital signature of an assembly. A strong name also consists of a public / private key pair used to encrypt/decrypt the assembly.
Strong Names allow assemblies to be versioned and authenticated. Signed Assemblies allow the assembly to have a unique identifier which allows multiple versions of an assembly to existing on a machine without colliding.
If you are developing assemblies that will be installed into the Global Assembly Cache (GAC) then the assembly must be strongly named.
The other benefit of creating strongly named assemblies is that the assembly can be authenticated. Because the strong name contains the private key of the author, you can be sure that the assembly was created by a particular author. A strongly named assembly can only reference other strongly named assemblies to ensure integrity.
Signing an Assembly
The first thing that you need to do is create a public/private key pair that will be used to encrypt the assembly.
To create a key/pair you can use the strong name utility:
sn -k <<em>file name</em>>
This will create the file containing the keys defaulting to RSA encryption. You should keep this file safe as you will need it for signing future assemblies if you wish to keep them authenticated.
Now, there are a few different methods for strongly naming an assembly, either from within Visual Studio or through the command line.
If you wish to give developers access to the private key you can simply add an attribute to the project. This code should go within the AssemblyInfo.cs file.
[assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile("c:mykey.sn")]
If you do not wish to give your developers access to your private key you can delay signing the assembly.
[assembly: AssemblyDelaySign(true)] [assembly: AssemblyKeyFile("c:mykey.sn")]
Then the assembly must have verification turned off otherwise the assembly will not load on the developer's machine:
c:> sn -Vr myassembly.dll
Finally, when the code is ready to be released you can fully sign the assembly using the sn.exe tool.
c:> sn -R myassembly.dll mykey.sn
Last updated on: Friday 23rd June 2017
There are no comments for this post. Be the first!