您可以在 GAC 中安装延迟签名程序集吗?CLR 通过 C# 第 4 版 [英] Can you install delayed signed assembly in GAC? CLR via C# 4th Edition

查看:40
本文介绍了您可以在 GAC 中安装延迟签名程序集吗?CLR 通过 C# 第 4 版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 CLR via c#(第四版) 并且在第 3 章关于强命名程序集作者说:

I was reading CLR via c# (Fourth Edition) and in chapter 3 about strong named assembly author says:

当编译器或 AL.exe 检测到您延迟签名时程序集,它将发出程序集的 AssemblyDef 清单条目,它将包含程序集的公钥.再次,存在公钥允许将程序集放置在 GAC 中.它也是允许您构建引用此程序集的其他程序集;这引用程序集将在其AssemblyRef 元数据表条目.创建结果时程序集,在生成的 PE 文件中为 RSA 数字留有空间签名.(实用程序可以确定需要多少空间公钥的大小.)请注意,文件的内容不会此时也进行了哈希处理.

When the compiler or AL.exe detects that you’re delay signing an assembly, it will emit the assembly’s AssemblyDef manifest entry, which will contain the assembly’s public key. Again, the presence of the public key allows the assembly to be placed in the GAC. It also allows you to build other assemblies that reference this assembly; the referencing assemblies will have the correct public key in their AssemblyRef metadata table entries. When creating the resulting assembly, space is left in the resulting PE file for the RSA digital signature. (The utility can determine how much space is necessary from the size of the public key.) Note that the file’s contents won’t be hashed at this time either.

此时,生成的程序集没有有效的签名.尝试将程序集安装到 GAC 中将失败,因为文件内容的散列尚未完成——文件似乎有被篡改.

At this point, the resulting assembly doesn’t have a valid signature. Attempting to install the assembly into the GAC will fail because a hash of the file’s contents hasn’t been done—the file appears to have been tampered with.

正如你所看到的,在第一段中,他说,当我们使用/delaysign 时,assemlby 的清单将包含 public key 这将允许它安装在 GAC.但在第二段中,他说,由于文件还没有用私钥签名,尝试将其安装到 GAC 将失败.那么,它是什么?你能不能安装它?

As you can see, in the first paragraph, he says, when we use /delaysign the assemlby's manifest will contain the public key which will aloow it be installed in GAC. But in the second paragraph, he says, since the file is not yet singed with private key, attempting to install it into GAC would fail. So, what is it? Can you install it or not?

推荐答案

好的,我找到了.它将不能安装在GAC中.我延迟了一个程序集并尝试在 GAC 中安装,但我收到此错误消息

Ok, I found it. It will not be able installed in GAC. I delay singed an assembly and tried to install in GAC, and I got this error message

Failure adding assembly to the cache: Strong name signature could not be verified. Was the assembly build delay-signed?

(以防万一有人在这里想同样的问题).您可以通过

( Just in case someone is here wondering the same ). You can skip the hash check by

SN -Vr assembly.dll

然后您可以将其安装在 GAC 中,然后重新散列(或者更确切地说是散列)您可以这样做,

and then you can install it in GAC and then to rehash (or rather hash) you can do this,

SN.exe -Ra assembly.dll yourStrongNameKey.PrivateKey

我唯一仍然想知道的是,你如何从 .snk 文件中提取这个私钥,似乎没有办法做到这一点.

The only thing I am still wondering is that how can you extract this private key from .snk file, there seems to be no way to do that.

这篇关于您可以在 GAC 中安装延迟签名程序集吗?CLR 通过 C# 第 4 版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆