473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Signing Assemblies with Key File (snk) Practices

I wish to know the industrial practices for signing
assemblies with key files.

I genereted a key file to sign my assemblies.

Should I sign all my assemblies with a single key files
or I shall generate one key file for each assembly?

Perhaps, I should generate a key file per group of
related assemblies?

Please advice
Jul 21 '05 #1
3 10662
Hi Joel,

All assemblies you produce can use the same public and private keys as long
as the assemblies
have unique friendly text names.

Next, you need to associate the 1,024-bit public key with an assembly. You
do this by telling the
compiler to read the contents of a key file, extract the public key from the
key file, and place the
public key into the definition of the assembly's identity. In effect, this
makes the public key an
extension of the friendly text name of the assembly. This also makes the
assembly name globally
unique because no other developer will be using the same 1,024-bit public
key as part of their assemblies' name.

You can know more about key files and how to generate them on the following
link:
[/keyfile]
http://msdn.microsoft.com/library/de...ifykeyfile.asp
HTH

Mona


"Joel Leong" <ch******@time.net.my> wrote in message
news:10****************************@phx.gbl...
I wish to know the industrial practices for signing
assemblies with key files.

I genereted a key file to sign my assemblies.

Should I sign all my assemblies with a single key files
or I shall generate one key file for each assembly?

Perhaps, I should generate a key file per group of
related assemblies?

Please advice

Jul 21 '05 #2
I would recommend that you generate a single key file for each solution
where the key files are used by the projects within the solution.
If you have assemblies that you re-use across projects:
There are two ways to reuse a project:
a) to include the code in another solution
b) to reference the compiled dll

if you are using (a) in your solutions, then I use the following logic:
a.1) if all of your projects are under a single source tree, then place
the key file closer to the root of the source tree, so that it is in a
directory that is a common ancestor to all of your source directories. That
way, your reference to the key file can still be a relative reference.
a.2) if your shared library is not in a common source tree but you still
intend to share source, place the key file in the same directory as the
AssemblyInfo file.

if you are using (b) in your solutions:
b.1) if all of the projects using the same key file are related, then
use (a.1).
b.2) If the projects are unrelated, use (a.2)

In your assemblyinfo.cs file, ALWAYS use a relative path location. I know
it is a hassle to put in a filename like
"..\..\..\..\..\..\..\..\..\keyfile.snk" However, doing so will allow the
code to be compiled on any developer's workstation simply by fetching the
entire source tree from version control. (this includes for build
machines). If you code "C:\a\b\c\keyfile.snk" and get the source tree onto
the D: drive of a build machine, none of your projects will compile.
Depending on what was on that machine before the compile was initiatited,
the error messages that appear can be anywhere from small (a few lines
pointing at the assemblyinfo file) to severe (hundreds of lines of errors
because an obsolete version of one or more common dlls was on the target
machine).

do not share key files between projects.

Note that key files are used to sign assemblies for the GAC. If you would
also like to sign controls for download to IE, you will need a different set
of procedures. The procedures above are for signing for the GAC and nothing
more.

HTH
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Joel Leong" <ch******@time.net.my> wrote in message
news:10****************************@phx.gbl...
I wish to know the industrial practices for signing
assemblies with key files.

I genereted a key file to sign my assemblies.

Should I sign all my assemblies with a single key files
or I shall generate one key file for each assembly?

Perhaps, I should generate a key file per group of
related assemblies?

Please advice

Jul 21 '05 #3
Joel Leong wrote:

I talk about signing files on the third section of my fusion workshop
(http://www.grimes.demon.co.uk/workshops/fusionWS.htm).
I wish to know the industrial practices for signing
assemblies with key files.

I genereted a key file to sign my assemblies.

Should I sign all my assemblies with a single key files
or I shall generate one key file for each assembly?

Perhaps, I should generate a key file per group of
related assemblies?


Look at the purpose for the key pair:

1) gives your assemblies a strong name
2) associates the assemblies as coming from the same publisher
3) signs your assemblies to prevent tampering

The use in the strong is that the key is unique and hence the assembly name
is unique, so if another assembly uses your library Fusion knows that it
should load *exactly* the right version, no other version will do. Since you
generate the key pair, the pair is associated with you. This does not say
who you are (a vertificate will do that) but it does say that if you
published assembly X with a key, and the user has an assembly Y signed with
the same key, then Y was also written by you. This is important because your
users could decide that they want to trust all assemblies from you and so
this is quite simple to do: trust all assembleis with the same public key.
When your assembly is signed a hash of the assembly is signed with the
private key and stored in the assembly along with the public key, so when
the assembly is loaded the hash is generated again and compared with the
hash stored in the assembly after it is decrypted with the publis key. If
the two hashes are different then the assembly has been tampered with since
it was published, and so it is not loaded.

So my advice is to have a *single* key pair for *all* the assemblies you
write. Keep that key pair safe (use delay signing if necessary
http://www.grimes.demon.co.uk/worksh...m#Example_3_8). That
way a user will be able to trust all of your assemblies. If you have lots
and lots of keys (one key per application, or a key for a group of
assemblies) then the keys are no longer useful as a way to identify the
publisher.

Richard
--
www.richardgrimes.com
my email ev******@zicf.bet is encrypted with ROT13 (www.rot13.org)
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tom Dacon | last post by:
If you're not putting assemblies in the GAC, but are referencing shared code with copylocal=true into the projects that use them, is there any value to signing the assemblies? In the environment...
1
by: serge calderara | last post by:
Dear all, I have different asseblies that I would like to sign in order to place them in the GAC. For that I first create a keypair at the same place as my solution file with : sn -k lang.snk...
9
by: Invalidlastname | last post by:
Hi, We developed some assemblies which use EnterpriseServices queued components. In order to use EnterpriseServices, these assemblies need to be installed into GAC. I used the pre-build and...
0
by: Jonas Blunck | last post by:
Hi all, I'd like to sign an ASP.NET assembly with our private/public key pair when I build it in VS (not by using al from the commandline). I've added the AssemblyKeyFile attribute in...
3
by: Joel Leong | last post by:
I wish to know the industrial practices for signing assemblies with key files. I genereted a key file to sign my assemblies. Should I sign all my assemblies with a single key files or I shall...
1
by: Jason Richmeier | last post by:
I have encountered an error while attempting to sign an assembly. I have become quite frustrated since I seem to be going in circles and making no progress. Hopefully someone will have the magic...
3
by: Janiek Buysrogge | last post by:
Hi, In my ActiveX component, which is written in .NET, I use a couple of GUI libraries I found on the net, with nicer group boxes and buttons. For using .NET assemblies as ActiveX components...
6
by: Larry | last post by:
When compiling, i get the following error. Preparing resources... Updating references... Performing main compilation... vbc : error BC30145: Unable to emit assembly: Referenced assembly...
6
by: raylopez99 | last post by:
Anybody use Strong Name Signing? I think this is used by default for Resource files, which is one reason perhaps I can't get my resource files to work (somehow the public key is messed up, perhaps...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.