Web Design that taps into the haromny and vision of your dreams.

Creating Strong Named Assemblies in Microsoft .Net

How to sign and create strong named assemblies

Written By on in C#

378 words, estimated reading time 2 minutes.

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.

Using Visual Studio Series
  1. Getting Started with Visual Studio
  2. Using the Visual Studio Integrated Development Environment
  3. Using the Visual Studio Debugger
  4. XML Documentation in Visual Studio
  5. Using Microsoft .Net Command Line Tools
  6. What is an Assembly in Microsoft .Net?
  7. Creating and Using a .NET Assembly in C#
  8. Creating and Implementing Satellite Assemblies
  9. Creating Strong Named Assemblies in Microsoft .Net
  10. Visual Studio Task List
  11. Resources and Localisation in C# Projects
  12. Localising Microsoft .Net Applications with C#
  13. Using Resource Files in C# Applications
  14. Using XSD Tool to Generate Classes from XML
  15. 10 Visual Studio Tools You May Not Know About

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!


Leave a Reply

Your email address will not be published.

If you find something abusive or that does not comply with our terms or guidelines please flag it as inappropriate.

Copyright © 2001-2018 Tim Trott, all rights reserved. Web Design by Azulia Designs

This web page is licensed for your personal, private, non-commercial use only.

Disclaimer, Privacy & LegalSitemapContact Me