加密,签名,验证和解密加密
我正在使用win32加密加密来加密并签署消息,然后验证签名并解密消息。
每件事都很好,直到我意识到CryptSignHash()将从我的数据中签署计算出的哈希并生成签名。意思是,在另一侧(收件人侧),收件人将需要接收签名和密码(分开),这是我不想要的。
我想将签名与一个单个容器中的加密消息结合在一起,然后将其全部发送在一起,然后收件人能够验证和解密。
我使用API的顺序如下:
CryptAcquireContext()
CryptGenKey()
CryptExportKey()
CryptImportKey()
CryptEncrypt()
CryptCreateHash()
CryptHashData()
CryptSignHash()
CryptVerifySignature()
CryptDecrypt()
有没有使用证书存储的方法?
I'm using win32 cryptoAPIs to encrypt and sign a message then verify a signature and decrypt the message.
every thing worked fine until I realized that the cryptSignHash() will sign the calculated hash from my data and generate a signature. Meaning, on the other side (the recipient side) the recipient will need to receive the signature and the cipher msg (separated), which is something I don't want.
I want to combine the signature with the encrypted message in one single container and send it all together and then the recipient will be able to verify and decrypt it.
my order of using the APIs was as the following:
CryptAcquireContext()
CryptGenKey()
CryptExportKey()
CryptImportKey()
CryptEncrypt()
CryptCreateHash()
CryptHashData()
CryptSignHash()
CryptVerifySignature()
CryptDecrypt()
Is there a way without using the certificate stores?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您从根本上误解了这个过程应该如何工作。在您呈现的特定情况下(将哈希签名和加密消息发送给收件人)也需要包括您的公钥。
收件人将使用您的公钥来解密哈希签名,并验证它是否与加密消息的哈希相匹配。这就是收件人可以用这些信息来完成的,即验证加密消息是否有效,并源自您。
收件人将无法解密加密的消息,因为他没有用于加密的私钥!
通常,该消息应使用对称密钥算法(例如AES)加密。签名和验证是通过不对称的私人/公钥算法(例如RSA)完成的。
例如,您的方案可以按以下方式扩展:
如您所见,这是一个相当复杂的过程。可以以某种方式简化较短的消息。如果消息短于RSA密钥的长度,则可以跳过AES加密并使用收件人的公共RSA密钥来加密整个消息,但是在现实世界中,情况通常不是这种情况。
I think you fundamentally misunderstood how this process is supposed to work. In your particular scenario that you presented (sending the hash signature and the encrypted message to your recipient) you will also need to include your public key as well.
The recipient will use your public key to decrypt the hash signature and verify if it matches the hash of the encrypted message. That is all the recipient can do with this information, namely verify that the encrypted message is valid and originates from you.
The recipient will not be able to decrypt the encrypted message because he doesn't have your private key that was used to encrypt it!
Usually the message should be encrypted with a symmetric key algorithm (such as AES). The signing and verifying is done with an asymmetric private/public key algorithm (such as RSA).
For example, your scenario could be expanded as follows:
As you can see this is a rather complicated process. It can be simplified somehow for shorter messages. If the message is shorter than the length of the RSA key then you can skip the AES encryption and use your recipient's public RSA key to encrypt the whole message but in real world this isn't usually the case.