如何创建正确的签名以提交到 PHP 服务器?

发布于 2024-12-08 04:30:17 字数 255 浏览 5 评论 0原文

我有一个具有已知公钥的服务器:P。用户 u 需要向服务器发送一些数据。因此,他发送用P加密的(数据)以及sha256(数据)作为签名。 A. 这安全吗? B. 明文传输哈希值是否构成信息泄露?欢迎各种类型的攻击。注意:中间的人不应该比假装的人更好。

据我所知,如果数据发生更改,攻击者无法重新计算新文本的正确哈希值。如果创建新数据来替换给定信息,那么我们就会冒充人。如果哈希值被丢弃或不正确,则服务器会出错。我错过了什么吗?哈希值是否应该包含在加密信息中?

谢谢!

I have a server with a known public key: P. User u needs to send the server some data. Therefore, he sends (data) encrypted with P along with sha256(data) as the signature. A. is this secure? B. Is it an information leak transmitting the hash in plaintext? All types of attacks welcome. Note: man in the middle should be no better than man pretending to be.

As far as I see it, if the data is changed the attacker cannot recompute the correct hash of the new text. If new data is created to replace the given information then we have man pretending to be. If the hash is dropped or is incorrect then the server errors. Am I missing something? Should the hash be included in the encrypted information?

Thanks!

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

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

发布评论

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

评论(2

小忆控 2024-12-15 04:30:17

我有一个具有已知公钥的服务器:P。用户 u 需要向服务器发送一些数据。因此,他发送了用P加密的(数据)以及sha256(数据)作为签名。

  • A.这安全吗?
  • B.以明文形式传输哈希值是否构成信息泄露?欢迎各种类型的攻击。<​​/li>

注意:中间的人不应该比假装的人更好。

您在这里构建的内容类似于 MAC 和加密,只不过相反对于 MAC 来说,它只是一个哈希函数。这不是一个好的设计。

相反,使用专用的密封 API(sodium_crypto_box_seal()openssl_seal() 等)来消除复杂性并公开简单的安全公钥加密(使用 AEAD)模式)。

如果您想单独发送 sodium_crypto_sign_detached($message, $signingKey) 到服务器,也可以。

I have a server with a known public key: P. User u needs to send the server some data. Therefore, he sends (data) encrypted with P along with sha256(data) as the signature.

  • A. is this secure?
  • B. Is it an information leak transmitting the hash in plaintext? All types of attacks welcome.

Note: man in the middle should be no better than man pretending to be.

What you've built here is something like MAC and encrypt, except instead of a MAC it's just a hash function. That's not a good design.

Instead, use a dedicated sealing API (sodium_crypto_box_seal(), openssl_seal(), etc.) that abstracts the complexity away and exposes simply secure public-key encryption (using an AEAD mode).

If you want to separately send sodium_crypto_sign_detached($message, $signingKey) to the server, that's fine too.

-小熊_ 2024-12-15 04:30:17

如果是为了数据传输,请查看 PHP 的 Mcrypt 扩展。去年,我在一个项目中使用了它,其中一个基于 PHP 的社交网站需要安全地将数据传入和传出用 C# 编写的外部报告系统。

If it's for data transfer, check out PHP's Mcrypt extension. I used it in a project last year where a PHP-based social networking website needed to pass data securely to and from an external reporting system written in C#.

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