
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Preventing Malicious Modifications to an Assembly
|
981
SN -k MyKeys.snk
This line creates your key pair in a file called MyKeys.snk. Since this file contains
both your public and private keys, you need to guard it carefully; store it only on a
machine that’s locked down enough to be considered highly trusted. Never make
copies of this key, and store it only on a highly trusted machine or on media that are
easy to secure.
Now that you have a key pair, you can get the public key from the pair in order to be
able to delay-sign your assemblies. Delay-signing allows day-to-day development to
continue on the assemblies while a trusted system holds the public-private-key pair
file (MyKeys.snk) for final signing of the assemblies.
In order to extract the public key from your key pair, use the
-p switch on SN.exe to
produce the MyPublicKey.snk file that holds your public key:
SN -p MyKeys.snk MyPublicKey.snk
Now you can delay-sign the assembly using the public key. You should not place the
public key in two assembly-level attributes shown here, as you would have done in
previous versions of VS.NET:
[assembly: System.Reflection.AssemblyKeyFile("MyPublicKey.snk")]
[assembly: System.Reflection.AssemblyDelaySign(true)]
Microsoft has deemed this a security risk. Instead, there is now a tab on the project ...