安全方面我如何正确使用 GUID?

发布于 2024-09-13 09:50:19 字数 577 浏览 0 评论 0原文

阅读了有关guid的答案,这相当不错有趣的。 GUID 似乎是基于时间的,v1 使用 MAC 地址,v4 使用 RNG。

来自 wiki

WinAPI GUID 的密码分析 生成器表明,由于 V4 GUID 的序列是伪随机的; 充分了解内部情况 状态,可以预测 先前和后续值。

我需要担心这个吗?比如说为用户生成cookie数据时?或密码重置键?

我的问题是如何正确使用 GUID 以及如何防止创建相同的 GUID(例如通过在同一毫秒内创建的同一台计算机上的两个线程)以及如何以不会泄露以前的密钥的方式使用它。我从使用异步 RNG 切换到同步 RNG(线程之间锁定)到 GUID,现在我认为这可能存在问题。

I read an answer about guid and it was fairly interesting. It seems that GUID is based on time and v1 uses a MAC address with v4 using a RNG.

From the wiki

Cryptanalysis of the WinAPI GUID
generator shows that, since the
sequence of V4 GUIDs is pseudo-random;
given full knowledge of the internal
state, it is possible to predict
previous and subsequent values.

Do i need to worry about this? say when generating cookie data for users? or password reset keys?

My question is how do i use GUID properly and how do i prevent creating the same GUID (say via two threads on same machine created during same millisecond) and how do i use it in a way it wont reveal previous keys. I switch from using async RNG to sync RNG (locking between threads) to GUID and now i think there may be a problem with this.

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

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

发布评论

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

评论(2

狼性发作 2024-09-20 09:50:19

你不需要担心这个。

您不会使用 .Net 生成重复的 Guid。

如果可能的话,你会到处抱怨。世界各地的人们都在以难以想象的速度在 .Net 中大量生产新的 Guid,这种速度是你我永远无法企及的,而且没有一个生成重复的产品。

也无需担心线程。 Guid.NewGuid() 调用保证是线程安全的。多核不会有什么区别。在您能找到的最快的服务器上尽可能快地生成它们,您仍然不会遇到问题。

说真的,这没什么值得担心的。

You don't need to worry about this.

You will not generate duplicate Guids with .Net.

If it was possible you would here complaints all over the place. All around the world people are churning out new Guids in .Net at unfathomable rates, speeds that you or I will never approach, and none of them have generated duplicates.

No need to worry about threading either. The Guid.NewGuid() call is guaranteed to be thread safe. Multi-core won't make a difference. Generate them as fast as you can on the fastest server you can find and you still won't have a problem.

Seriously, its just not something to worry about.

我很OK 2024-09-20 09:50:19

答案是使用基于随机数的 GUI。

早期的计划实际上被打破了。处理器速度的提高现在可以根据相同的毫秒刻度生成数百个 GUID。虚拟化意味着您可以与操作系统的多个实例共享相同的 MAC 地址。多处理器机器的兴起意味着两个进程可以在同一台机器上在同一时钟周期内生成 GUID。

虽然仍然可以使用基于随机数的方案生成重复项,但其几率与在另一个星系的特定行星上中奖的几率大致相同。

The answer is to use the random number based GUI.

The eaerlier schemes are effectly broken. Increases in processer speed you can now generate several hunded GUIDs based on the same millsecond tick. Virtualisation means you could be sharing the same MAC address with several insances of the OS. The rise of multiprocessor machines means two processes can be generating GUIDs on the same machine in the same clock tick.

While its still possible to generate duplicates using the random number based scheme the odds are about the same as winning the lottery on a particular planet in another galaxy.

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