Key Files SNK and assemblyinfo. CS

Source: Internet
Author: User

When I heard about the SNK file, I probably guessed it was related to the signature and verification, and thought it was for Software encryption. In fact, in. net, SNK is usedProgramSet signature to ensure the validity of the application set. It has nothing to do with Software Encryption

  Reason for strong-naming assembly: DLL in WindowsHell problem (two different companies may develop an assembly with the same name. If an assembly with the same name is placed in the same directory, assembly overwrites may occur, the last installed program Assembly overwrites the previous Assembly, which may cause the application sequence to fail to run normally ). Therefore, it is not enough to distinguish an assembly 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 types of assembly/two deployment methods:. Net supports two types of Assembly: weak naming assembly and strong naming assembly (note: There is no weak naming assembly in the. NET Framework, 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.

Strong naming principles in vs2005:
Use sn.exe to generate a file, such as samplekey. SNK. the original English text of this file is string name key file, and then use encryptedAlgorithmGenerate a samplekeypublic. SNK Based on samplekey. SNK. Finally, extract a public key Token Based on samplekeypublic. SNK.
, Public Key token is a 16-digit mixed number of letters (I am not sure whether it is a hexadecimal number): the general process is as follows:

Samplekey. SNK -- according to certain algorithms --> samplekeypublic. SNK ----> Public Key token
So we only need samplekey. SNK and Public Key token, and samplekeypublic. SNK is useless.

Actual OperationAs follows:
1. Open the SDK command prompt or Visual Studio 2005 command prompt in vs2005, instead of Windows cmd.
2. Enter Sn-K samplekey. SNK. The obtained file is in the current folder of the command prompt (Microsoft calls the folder a directory rarely, and the most important point is folder)
3. Enter Sn-P samplekey. SNK samplekeypublic. SNK
4. Enter Sn-T samplekeypublic. SNK to get the public key token.

Open vs2005, find the project, right-click "project name", find "property", and there is a "signature" tab in "properties", and hook
"Sign the Assembly", and then "select strong name key file". After the operation is completed, remember to save and compile

 

 

========================================

 

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) use the SNK file to generate a strongly-named Assembly so that an assembly can be assigned the full-trust attribute or added to GAC. Generate strong-named assembly in vs. net. You only need to add it in assemblyinfo. CS.CodeCompile the Code:


[Assembly: assemblydelaysign (false)]
[Assembly: assemblykeyfile ("... \ .. \ keypair. SNK")]
[Assembly: assemblykeyname ("")]

 

reason for strong-naming Assembly: DLL hell issues in Windows (two different companies may develop an 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.

 

 

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.