安全地将数据从一个站点发送到另一个站点?
我要将一些数据从一个网站发布到另一个网站。 我需要一种方法让接收网站确保数据是从发送网站发送的,而不是由其他恶意用户发送的。 我正在使用PHP4。
我怎样才能做到这一点?
谢谢!
I am going to post some data from one website to another website. I need a way for the receiving website to be sure that the data was sent from the sending website and not sent by some other malicious user. I am using PHP4.
How can I do this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只需使用双向 ssl 即可。 客户端使用 ssl 证书在服务器上对自身进行身份验证,而不仅仅是相反。
因此服务器知道他获取数据表单的是正确的客户端。
客户端知道他将数据发送到正确的服务器
Just use two-way ssl. The client authenticates itself at the server with a ssl certificate not only the other way around.
So the server knows it's the right client he gets the data form.
The client knows he sends the data to the right server
对于仅 PHP 的解决方案:
如果您可以保守秘密(两端),那么您可以使用 Keyed-Hash 消息身份验证代码(HMAC 或 KHMAC)。
这个概念是,如果两端都有相同的秘密,则可以发送端哈希(消息+秘密),接收端哈希(消息+秘密)。 如果哈希值匹配,则您拥有有效的消息。
秘密就是关键(双关语)。 因为如果没有秘密,攻击者就不可能更改消息并生成将在接收端进行验证的新哈希。
下面是一些示例 PHP 代码:
如果您希望防止黑客重新发布相同的消息,从而提高安全性,您可以向每个请求添加随机请求标识符,并确保永远不会接受相同的哈希值。
免责声明:与所有安全敏感代码一样,在信任敏感数据之前应该经过同行评审和验证。 通过对该主题的研究,或者更好的是,使用处理此类验证+身份验证的现有库。
For a PHP-only solution:
If you can keep a secret (on both ends), then you can use a self-implemented variant (yes, a variant) of Keyed-Hash Message Authentication Code (HMAC or KHMAC).
The concept is that if you have the same secret on both ends, you can hash (message+secret) on the sending end, and hash (message+secret) on the recieving end. If the hashes match, then you have a valid message.
The secret is the key (pun intended). Because without the secret, it is infeasible that an attacker could alter the message AND generate a new hash that will verify on the receiving end.
Here is some example PHP code:
If you wanted additional security from a hacker re-posting the same message, you could add a random request identifier to each request, and ensure that the same hash is NEVER accepted.
DISCLAIMER: this as with all security sensitive code should be peer reviewed and verified before being trusted with sensitive data. Do through research on the topic, or better yet, use an existing library that handles this type of verification+authentication.
jitter 的解决方案(双向 SSL)有效。 然而,一种可能更简单的方法是使用单向 SSL(验证接收服务器)和基本身份验证。 SSL 提供机密性,Basic Auth 对客户端进行身份验证。
jitter's solution (bidirectional SSL) works. However, a possibly simpler way is to use one-way SSL (authenticate receiving server) and Basic Auth. SSL provides confidentiality and Basic Auth authenticates the client.
我会考虑使用 GnuPG: http://devzone.zend.com/article/1265
I'd look into using GnuPG: http://devzone.zend.com/article/1265
我投票支持 SSL,但作为替代方案。
如果两个站点都知道密钥 (SK),则
My vote is for SSL, but as an alternative.
If both sites know a secret key (SK) then,