如何存储 IP 地址以供比较而不泄露?
为了打击投票欺诈,我需要将 IP 地址存储在数据库中,但我想让它们匿名。我需要的唯一信息是两个地址是否相同......我想。
要防止公共网站中的投票操纵,比较 IP 地址是否相等就足够了吗?
出于透明度/验证目的,我希望允许用户下载投票数据。因此,我必须以合适的方式对 IP 地址进行哈希处理。您建议使用哪种哈希方法?为什么?
To fight vote fraud, I need to store IP addresses in my database but I want to make them anonymous. The only information that I need is if two addresses are the same ... I think.
To prevent voting manipulation in a public web site, is it enough to compare IP addresses for equality?
For transparency/verification purposes, I'd like to allow users to download the voting data. Therefore, I have to hash the IP addresses in a suitable way. Which hash method do you suggest and why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
比较公共 IP 是不够的。您只允许来自少数国家和拥有一个外部 IP 的公司投一票。
最好的方法是使用多种方法来检测假选票。
要匿名 IP,只需对 IP 进行密钥哈希即可。
Comparing public IPs wont be enough. You will let only one vote from few countries and from corporates, which have one external IPs.
Best way to do it is use multiple methods to detect the fake votes.
For anonymizing the IP just make keyed hash of IP.
我过去做过一些投票功能,并使用 IP 作为唯一约束。缺点是人们可能共享公共IP。
您可以将 cookie 和 IP 结合起来。人们是否作弊,这完全取决于投票的重要性。
我会使用简单的 MD5 哈希值。
I've done some voting functionaly in the past and I've used IP as the unique constraint. The drawback is that people may share public IP.
You could combine cookie and IP. It all depends of the importance of the voting if people are cheating or not.
I would use a simple MD5 hash.
一旦网关后面的人投票了,这将阻止 NAT 网关后面的许多人投票。你真的想这么做吗?
That will prevent lots of people who are behind NAT gateways from voting, once someone behind the gateway has voted. Do you really want to do that?
我会对 IP 地址进行哈希处理,并为每次民意调查保留已投票者的哈希值列表和答案列表。不要将答案与哈希值结合起来。这样,你的哈希值到底有多好并不重要。
除了存储 ip 之外,您还可以考虑在客户端上放置一个 cookie,例如对于拥有笔记本电脑的人,他们连接到不同的网络,从而能够从不同的 ip 进行投票。
还要意识到,通过允许 ip 投票一次,您就允许 NAT 或代理后面的人投票一次。这可能意味着整个公司只能投票一次。你需要考虑一下你是否可以接受。
I would hash the IP adress, and for each poll, keep a list of hashes of people who have voted, and a list of answers. Don't couple the answer with the hash. That way, it doesn't even matter how good your hashing is exactly.
You could consider in addition to storing the ip, also putting a cookie on the client, for people with laptops for instance, who connect to different networks and thereby are able to vote from different ip's.
Also realize that by allowing an ip to vote once, you're allowing people behind a NAT or proxy to vote once. That could mean that an entire company can only vote once. You need to consider whether that's acceptable to you.
我认为防止投票欺诈的最好方法是使用身份验证方法。但是您需要一些无需身份验证的公共网站。是的?
那么你的想法是对的,IP验证,将IP地址与哈希值保存在一张表中。
I think the best way to prevent vote fraud is with authentication method. But you need something for Public website without authentication. Yeah?
Then your thoughts is right, IP verification, save the IP address in one table with the hash.
使用公共盐进行哈希显然不能保持 IP 的私密性(IP 仅有 40 亿个,很容易暴力破解)。
所以你需要将盐保密,此时它基本上就成为了关键。因此,您可以使用对称加密代替散列,例如 AES 也是秘密密钥。并且不会有显着差异。除了您自己(拥有密钥的人)逆转加密比逆转哈希稍微容易一些之外。
您可以做的另一件事是使用明显短于 32 位的哈希值。这样,您就可以防止仅因为有许多 IP 与单个哈希匹配而对 IP 进行逆向操作。当然,每次投票也会阻止许多其他 IP。这是否可以接受取决于您的用例。
Hashing with a public salt obviously doesn't keep the IPs private(there are only 4 billion of them, easy to brute-force reverse).
So you need to keep the salt private, at which point it basically becomes a key. So instead of hashing you could use a symmetric encryption like AES is a secret key too. And there would be no significant difference. Except that it's slightly easier for yourself(who has the key) to reverse the encryption than to reverse the hash.
One other thing you could do is use a hash significantly shorter than 32 bits. That way you prevent reversing of an IP simply because there are many IPs matching a single hash. But of course each vote then blocks a number of other IPs too. If that's acceptable depends on your use-case.