SNK and PDF

Source: Internet
Author: User

SNK 1 is used to prove that the generated assembly was released by you; 2. If the Assembly you write is to be used on multiple applications, the Assembly must have a unique name, this strong name is part of the unique assembly name. 3 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.

Two methods to create an SNK File

1. In the command line mode of vs.net (start --> program --> Microsoft Visual studio.net 2003 --> visual studio.net tool --> visual studio.net command prompt), enter Sn-k xxxx. SNK.

XXXX. SNK is the digital signature file you need.

Use: first store the SNK file to a folder (key). In the assemblyinfo. CS file, it contains all version numbers and reference of all digital signature files. We will modify the [Assembly: assemblykeyfile ("")] In this file to [Assembly: assemblykeyfile (@ "/key/xxxx. SNK")]

This completes the creation.

2 in Visual Studio 2005, key pairs can be generated through the integrated development environment (IDES) of C #, Visual Basic, and Visual J, you can sign an assembly without using sn.exe to create a key pair. The above ide has the "signature" tab in the "Project Designer. Like the SNK file, the pfx file can be used to add a strong name to the Assembly. However, the pfx file requires a password when it is added. If you want to create an SNK file, do not select "use password to protect the key file". This will generate a file with the SNK extension.

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

 

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:
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. 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 in Windows (two different companies may develop an assembly with the same name. If you place the Assembly with the same name in the same directory, then, the Assembly overwrites the Assembly. The Assembly that is finally installed overwrites the previous Assembly, which may cause the application to run abnormally ). 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, such
Using system. reflection;
Using system;
Using system. runtime. constrainedexecution;
Using system. runtime. compilerservices;
Using system. runtime. interopservices;

// Whether the public language specification (CLS) is met)
[Assembly: clscompliant (true)]
// Control the accessibility of all types of COM in the dataset
[Assembly: comvisible (false)]
// Reliable agreement between the author of the Code and the developers of the Code
[Assembly: reliabilitycontract (consistency. willnotcorruptstate, Cer. mayfail)]

// For general information about the assembly, use the following attribute set
// Control. You can modify these attribute values.
// Information associated with the Assembly.
[Assembly: assemblytitle ("testpetshop. sqlserverdal")]
[Assembly: assemblydescription ("t test petshop4.0")]
[Assembly: assemblyconfiguration ("")]
[Assembly: assemblycompany ("CCP")]
[Assembly: assemblyproduct ("testpetshop. sqlserverdal")]
[Assembly: assemblycopyright ("Copyright (c) CCP 2007")]
[Assembly: assemblytrademark ("")]
[Assembly: assemblyculture ("")]

// Set comvisible to false to make the type in this Assembly
// The COM component is invisible. If you need to access the types in this Assembly from com,
// Set the comvisible attribute of this type to true.
[Assembly: comvisible (false)]

// If this project is made public to com, the following GUID is used for the ID of the Type Library
[Assembly: GUID ("dc8b813c-f361-476f-8cf1-8fab3d57ced7")]

// The Assembly version information consists of the following four values:
//
// Main version
// Version
// Internal version number
// Revision No.
//
[Assembly: assemblyversion ("1.0.0.0")]
[Assembly: assemblyfileversion ("1.0.0.0")]

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.