Uncategorized

Signing .Net Assemblies

April 23, 2005

author:

Signing .Net Assemblies

If you wish to create strong named assemblies in .Net, you need to sign them. This is done using a key that you reference through the project’s AssemblyInfo.cs or AssemblyInfo.vb file. There are three attributes related to signing:

[assembly: AssemblyDelaySign(false)] Used to allow signing of the assembly with only the public key. This allows the assembly to be used during development without having to share the private key.

[assembly: AssemblyKeyFile(“”)] Used to specify the path to a key file.

[assembly: AssemblyKeyName(“”)] Used to specify the name of a key to use from the Crypto Service Provider (CSP).

If you are going to sign all your assemblies, then the AssemblyKeyName is the best option as it does not require you to remember a path to the key file each time you create a new project. It’s much easier to remember a simple name associated with the key. Here’s how you would sign an assembly using the CSP:

1) Generate a key pair:  sn -k MyCompany.snk

2) Install into the CSP:  sn -i MyCompany.snk MYCOMPANY

3) Use in your code:  [assembly: AssemblyKeyName(“MYCOMPANY”)]

Founder NftyDreams; founder Decentology; co-founder DNN Software; educator; Open Source proponent; Microsoft MVP; tech geek; creative thinker; husband; dad. Personal blog: http://www.kalyani.com. Twitter: @techbubble
Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.