Digital signature file (. SNK)

Source: Internet
Author: User
Digital signature file (. SNK) 2006-12-06

The digital signature file is used to prove that the generated assembly was published by you. Moreover, if the Assembly you write is to be used in multiple applications, the Assembly must have a unique name, this strong name is part of the unique assembly name.

In addition, as long as you protect your SNK files from being published, no one can impersonate your published assembly.

The principle of strong name signature is asymmetric signature verification algorithm.

First, you use the sn.exe command line program to generate a. SNK key file, which contains two parts.
1. The private key is what generates the verification code During vs.net compilation.
2. The public key is packaged into the publickey part of the assembly metadata during compilation.

In addition, the verification code can only be generated using the private key. Only the verification code generated using the private key can pass. Net CLR verification.

When the CLR verifies the assembly, it reads the public key to generate the verification object. After the Assembly is generated, it verifies the content of the entire assembly. The verification code is compared with the verification code in the Assembly. If the verification code matches, it passes, if they do not match, the Assembly has been modified. CLR rejects the Assembly from being loaded and considers that the required assembly is not found. A filenotfoundexception exception is thrown.

For example, Microsoft's. system. DLL, system. web. DLL and so on, all of which have undergone strong name verification to ensure that others can only use these class libraries, but cannot modify them, and ensure that these assemblies are released by Microsoft. In addition, these assemblies are stored in the shared directory and require a strong name.

Sn is a strong name, which can be used as. DLL file key, if you use another *. the SNK file replaces the original file ,. the DLL cannot be compiled, and of course it cannot be run.
You may have not re-compiled the. dll file.

The SNK file is used in .netto store the encrypted or encrypted storage file, and the sn.exe command in .netcan be used to generate the encrypted SNK file, such as "Sn-K keypair. SNK ".

SNK itself is only used to store asymmetric keys, but it can be used wherever encryption and signature are needed:
1) generate a strongly-named assembly using the SNK file so that an assembly can be assigned the full-trust attribute or added to GAC. To generate strong-named assembly in vs. net, you only need to add the code and compile it in assemblyinfo. CS:
[Assembly: assemblydelaysign (false)]
[Assembly: assemblykeyfile (".. // keypair. SNK")]
[Assembly: assemblykeyname ("")]

Reason for strong-naming Assembly: DLL hell issues currently occurring in Windows (two different companies may develop assembly with the same name, if you place a set of programs with the same name in the same directory, the Assembly overwrites the Assembly. The Assembly that is finally installed overwrites the previous Assembly, as a result, the application sequence may not run properly ). From this point of view, it is not enough to distinguish a set of programs by name alone. CLR uses a strongly-named assembly to uniquely represent an assembly. A strongly-named Assembly contains four identifiers: name, version number, Language and Culture identifier, and a common/private key pair. Two assembly/two deployment methods :. net supports two types of Assembly: weak naming assembly and strong naming assembly (Note :.. NET Framework does not have a weak naming assembly, just to match the strong naming assembly ). Weak naming assembly and strong naming Assembly are in the same structure. They all adopt the PE file format, including the PE Header, CLR header, metadata, and list table. The difference is that a strongly-named assembly has a publisher's public/private key signature pair, which is used to uniquely identify the publisher of the Assembly. Through the public/private key pair, We can uniquely identify the Assembly, security policy, and Version Policy.

Assemblyinfo. CS is mainly used to set some parameters of the generated assembly-related general information DLL file.
See the following description:
// Remarks:
[Assembly: assemblydescription ("written as the strongest robbery class! ")]
// Product Name
[Assembly: assemblyproduct ("Wuwei search")]
// Company
[Assembly: assemblycompany ("Wuwei network")]
// Valid Trademark
[Assembly: assemblytrademark ("Inaction")];
// Internal name
[Assembly: assemblyculture ("")]
// Designer
[Assembly: assemblydescription ("Inaction class library")]
// Copyright
[Assembly: assemblycopyright ("")]
// Configuration file
[Assembly: assemblyconfiguration ("configuration")]
// Product Version: You can specify the product version as follows:
// The Assembly version information consists of the following four values:
//
// Main version
// Version
// Internal version number
// Revision No.
//
// You can specify all these values, or use the default values of the revision number and internal version number by pressing
// Use '*' as follows '*':
[Assembly: assemblyversion ("1. 0. *")]

After generating the DLL file, right-click it and check its properties. You will see the familiar content in it.

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 1467072

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 1642337

Sn-K file name. Snk (under DOS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.