如何使用强名称签署 .NET 程序集 DLL 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1220519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 13:06:05  来源:igfitidea点击:

How to sign a .NET Assembly DLL file with a Strong Name?

.netcode-signing

提问by guaike

I have an assembly which is not strong-named. I have no source code for it.

我有一个非强命名的程序集。我没有它的源代码。

I now need it to be signed. Is there a way to do this?

我现在需要签名。有没有办法做到这一点?

回答by Cheeso

If the original assembly is marked for delayed signing, then you can use the sn.exe tool.

如果原始程序集标记为延迟签名,则可以使用 sn.exe 工具。

If the original assembly is not so marked, then you can disassemble it with ildasm.exe, then re-asssemble it with ilasm.exe and specify the /key argument. References: [1][2].

如果原来的程序集没有这么标记,那么你可以用ildasm.exe反汇编它,然后用ilasm.exe重新组装它并指定/key参数。参考文献:[1] [2]

Example:

例子:

> ildasm /all /out=MYASSEMBLY.il MYASSEMBLY.dll
> ilasm /dll /key=key.snk MYASSEMBLY.il

回答by xmojmr

Easy way to sign 3rd party assembly is using the GUIversion of Assembly Strong Name Signer, available here: http://brutaldev.com/post/2013/10/18/NET-Assembly-Strong-Name-Signer.

签署第 3 方程序集的简单方法是使用 的GUI版本Assembly Strong Name Signer,可在此处获得:http: //brutaldev.com/post/2013/10/18/NET-Assembly-Strong-Name-Signer

It's source code is available on Github. Uses Mono.Cecilfor the dirty work. Available also as command linetool.

它的源代码可以在 Github 上找到。使用Mono.Cecil了肮脏的工作。也可作为command line工具使用。

I have found the recommended ildasm-> ilasmround trip suggested at several places cumbersome and better to be avoided.

我发现推荐的ildasm->ilasm在几个地方推荐的往返旅行很麻烦,最好避免。

I don't know how Assembly Strong Name Signerhandles multi-assembly dependencies. In case it does not , the problem and it's solution is described here (published 2008): http://buffered.io/posts/net-fu-signing-an-unsigned-assembly-without-delay-signing/

我不知道如何Assembly Strong Name Signer处理多程序集依赖项。如果没有,这里描述了问题及其解决方案(2008 年发布):http: //buffered.io/posts/net-fu-signing-an-unsigned-assembly-without-delay-signing/

回答by Joe Chung

Use the Strong Name Tool utility (sn.exe).

使用强名称工具实用程序 ( sn.exe)。

回答by Martin

Take a look at my StrongNameResigner. It can sign or resign an assembly and all assemblies that depend on it while also updating all references using a command like that:

看看我的StrongNameResigner。它可以对一个程序集和所有依赖它的程序集进行签名或重新签名,同时还可以使用如下命令更新所有引用:

StrongNameResigner.exe -a "c:\temp" -k "key.snk" Foo.Bar

回答by K T

You can sign the assembly with the help of VS command prompt.
Just type the path in VS cmd prompt where your project is physically present.

In VS cmd
<your project path>sn -k <name of your project>.snk

Then go to your project in Solution Explorer -> properties -> Signing -> check checkbox  
-> Browse to the key which is created using VS cmd.