您现在的位置: 无忧电子商务网 >> 信息学院 >> 程序开发 >> asp.net >> 正文

HOW TO: Create an Assembly with a Strong Name

作者:作者:未…    信息学院来源:网络收集    点击数:    更新时间:2006-8-28 我要参与讨论

  HOW TO: Create an Assembly with a Strong Name

--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual Studio .NET Beta 2

--------------------------------------------------------------------------------

IN THIS TASK
SUMMARY
Prerequisites
Creating an Assembly with a Strong Name
REFERENCES


SUMMARY
Assemblies can be assigned a cryptographic signature called a strong name, which provides name uniqueness for the assembly and prevents someone from taking over the name of your assembly (name spoofing). If you are deploying an assembly that will be shared among many applications on the same computer, it must have a strong name. This document describes how to create an assembly with a strong name.

back to the top

Prerequisites
This article assumes that you have installed and are familiar with Visual Studio .NET.

back to the top
Creating an Assembly with a Strong Name
Use the Strong Name tool (Sn.exe) that comes with the .NET Framework Software Development Kit (SDK) to generate a cryptographic key pair.

The following command uses the Strong Name tool to generate a new key pair and store it in a file called TestKey.snk:


sn -k Testkey.snk
Add the proper custom attribute to your source for the compiler to emit the assembly with a strong name. Which attribute you use depends on whether the key pair that is used for the signing is contained in a file or in a key container within the Cryptographic Service Provider (CSP). For keys that are stored in a file, use the System.Reflection.AssemblyKeyFileAttribute attribute. For keys that are stored in the CSP, use the System.Reflection.AssemblyKeyNameAttribute attribute.

The following code uses AssemblyKeyFileAttribute to specify the name of the file that contains the key pair.

NOTE : In Microsoft Visual Basic, the assembly level attributes must appear as the first statements in the file.

Visual Basic .NET Code
Imports System
Imports System.Reflection

<assembly:AssemblyKeyFileAttribute("TestKey.snk")>
C# Code
using System;
using System.Reflection;

[assembly:AssemblyKeyFileAttribute("TestKey.snk")]
back to the top
REFERENCES
For more information about the Strong Name tool (Sn.exe), see the following Microsoft .NET Framework Tools Web site:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfstrongnameutilitysnexe.asp
For more information about the .NET Framework SDK, see the following Microsoft Web site:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/nfstart/html/sdkstart.asp
For more information about global attributes, see the C# Programmer's Reference.

[1] [2] 下一页

在google里搜索更多HOW TO: Create an Assembly with a Strong Name

Google
Web www.51ec.org
【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
我来说两句 对此文章发表了评论
  昵 称: *必填    ·注册用户·
  评 分: 1分 2分 3分 4分 5分     严禁发表危害国家安全、政治、黄色淫秽等内容的评论,用户需对自己在使用本网站服务过程中的行为承担法律责任。本站管理员有权保留或删除评论内容,评论内容只代表机友个人观点,与本网站立场无关。  
评 论
内 容

 
评论列表 (最新 评论仅限网友观点!)

供求信息




| 设为首页 | 加入收藏 | 关于我们 | 广告服务 | 联系方式 | 友情链接 | 版权申明