如何使用公钥在 .NET 程序集中解密?

发布于 2024-07-15 18:15:49 字数 190 浏览 3 评论 0原文

.NET签名的程序集包含公钥,但是公钥在RSA中用于加密,那么.NET如何使用公钥对签名的程序集进行解密呢?

好的,签名的程序集包含哈希值,但哈希值是使用私钥而不是公钥加密的。 那么,为什么以及如何在 .NET 中使用私钥进行加密并使用公钥进行解密。 我的意思是,像 RSACryptoPad 这样的所有软件都使用公钥进行加密而不是解密。

.NET signed assemblies contain public key, but the public key is used for encryption in RSA, then how does .NET uses the public key for decryption of signed assemblies?

Ok, the signed assemblies contain the hash, but the hash is encrypted using the private key and not the public key. So, why and how in .NET private keys are used for encryption and public keys for decryption. I mean, that all software like RSACryptoPad uses the public key for encryption and not for decryption.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吻泪 2024-07-22 18:15:49

公钥-私钥对不用于加密整个程序集。 相反,它用于签署程序集。

稍微简化一下,要签署文件(例如程序集),您需要获取文件的哈希值,然后使用私钥对该哈希值进行加密。 使用该文件的人会通过创建文件本身的哈希值来验证您的签名,然后使用您的公钥解密加密的哈希值并确认这两个哈希值相同。 这证明了两件事:

  1. 该程序集来自声称来自的人 - 即您 - 因为它是使用您的私钥生成的。
  2. 该程序集尚未被其他人更改,因为您在发布程序集时创建的哈希值与当前的哈希值相同。 没有人可以更改签名的程序集,因为他们还必须对需要您的私钥的加密哈希进行相应的更改。

这篇维基百科文章中有更多关于数字签名的详细信息。

公钥-私钥对的伟大之处在于它们可以以任何方式工作。 因此,使用您的私钥加密的内容只能使用您的公钥解密,但使用您的公钥加密的内容也可以使用您的私钥解密。 后一种用法意味着,如果有人想向您发送某些内容,并且只有您可以使用您免费提供的公钥对其进行加密,但他们知道只有您使用您的私钥才能解密它。

由于密钥只能成对使用 - 使得 加密不对称 - 其他人不能简单地反转他们使用公钥进行的加密,以便将消息发送给您。

The public-private key pair is not used to encrypt the whole assembly. Instead it is used to sign the assembly.

Simplifying a little, to sign a file - such as an assembly - you take a hash of the file and then ecrypt that hash with your private key. Someone using the file verifies your signature by making a hash of the file themselves and then decrypting your encrypted hash using your public key and confirming these two hashes are the same. This proves two things:

  1. The assembly is from who is claims to be from - i.e you - as it has been produced with your private key.
  2. The assembly hasn't been altered by someone else as the hash you made when you released the assembly is the same as the current one. No-one can alter the signed assembly since they would also have to make corresponding changes to the encrypted hash which requires your private key.

There is a lot more detail about Digital Signatures in this Wikipedia article.

The great thing about public-private key pairs is that they work either way around. So something encrypted with your private key can be only decrypted with your public key but also something encrypted with your public key can be decrypted with your private key. This latter use means that if someone wants to send something to you and only you then then can encrypt it with your freely available public key but they know only you with your private key can decrypt it.

As the keys only work as a pair - making the encryption asymmetric - someone else can't simply reverse the encryption they've done with the public key to get the message to you.

方圜几里 2024-07-22 18:15:49

这个想法是,只能使用私钥创建签名,但此后任何拥有公钥副本的人都可以 >验证签名签名不需要解密——签名只需添加到纯文本程序集中即可。

The idea is that a signature can only be created using the private key, but after that anyone with a copy of the public key can validate the signature. No decryption is required for a signature--the signature is simply added on to the plain text assembly.

故人爱我别走 2024-07-22 18:15:49

对程序集进行签名的目的是验证其来源。 如果我签署我的程序集然后将其发送给您,您应该有理由确定它来自我并且在整个过程中没有被篡改。

The purpose of signing assemblies is to verify their source. If I sign my assembly then send it to you, you should be reasonably sure that's its come from me and it hasn't been tampered with along the way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文