如何使用公钥在 .NET 程序集中解密?
.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
公钥-私钥对不用于加密整个程序集。 相反,它用于签署程序集。
稍微简化一下,要签署文件(例如程序集),您需要获取文件的哈希值,然后使用私钥对该哈希值进行加密。 使用该文件的人会通过创建文件本身的哈希值来验证您的签名,然后使用您的公钥解密加密的哈希值并确认这两个哈希值相同。 这证明了两件事:
这篇维基百科文章中有更多关于数字签名的详细信息。
公钥-私钥对的伟大之处在于它们可以以任何方式工作。 因此,使用您的私钥加密的内容只能使用您的公钥解密,但使用您的公钥加密的内容也可以使用您的私钥解密。 后一种用法意味着,如果有人想向您发送某些内容,并且只有您可以使用您免费提供的公钥对其进行加密,但他们知道只有您使用您的私钥才能解密它。
由于密钥只能成对使用 - 使得 加密不对称 - 其他人不能简单地反转他们使用公钥进行的加密,以便将消息发送给您。
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:
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.
这个想法是,只能使用私钥创建签名,但此后任何拥有公钥副本的人都可以 >验证签名。 签名不需要解密——签名只需添加到纯文本程序集中即可。
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.
对程序集进行签名的目的是验证其来源。 如果我签署我的程序集然后将其发送给您,您应该有理由确定它来自我并且在整个过程中没有被篡改。
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.