如何.NET 4的GUID产生的? [英] How are .NET 4 GUIDs generated?

查看:234
本文介绍了如何.NET 4的GUID产生的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道了许多问题,这里以及雷蒙德的优秀(像往常一样)的post 。然而,由于算法创建的GUID显然是变了,我发现很难得到我的手任何先进的最新信息。该 MSDN 似乎尝试提供尽可能少的信息尽可能。

I am aware of the multitude of questions here as well as Raymond's excellent (as usual) post. However, since the algorithm to create GUIDs was changed apparently, I found it hard to get my hands on any up-to-date information. The MSDN seems to try and provide as few information as possible.

我们所了解的GUID如何在.NET 4中产生的?是什么改变了,它是如何影响安全(随机性),诚信(唯一性)?

What is known about how GUIDs are generated in .NET 4? What was changed, and how does it affect the security ("randomness") and integrity ("uniqueness")?

一个具体的方面我很感兴趣:在V1,这似乎是大约不可能产生相同的GUID一台机器上再次因为有一个时间戳和反介入。在V4,这已不再是这样(有人告诉我),所以有机会获得同样的GUID一台机器上... 增加的?

One specific aspect I'm interested in: In v1, it seems to be about impossible to generate the same GUID on a single machine again since there was a timestamp and counter involved. In v4, this is no longer the case (I was told), so the chance to get the same GUID on a single machine ... increased?

推荐答案

由于视窗2000 微软采用的是版本4的算法:

Since Windows 2000 Microsoft uses a version 4 algorithm:

在Windows 2000中,微软切换到第4版的GUID,因为嵌入的MAC地址被看作是一个安全隐患。 1

With Windows 2000, Microsoft switched to version 4 GUIDs, since embedding the MAC address was viewed as a security risk. 1

您可以看到,以及从.NET中生成一个GUID(从维基百科):

You can see that as well from a GUID generated in .NET (from Wikipedia):

第4版的UUID的格式XXXXXXXX-XXXX-4XXX-YXXX-XXXXXXXXXXXX任何十六进制数字为X,但只有一个8,9,A,或Y B。例如f47ac10b-58cc-4372-a567-0e02b2c3d479。

Version 4 UUIDs have the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx with any hexadecimal digits for x but only one of 8, 9, A, or B for y. e.g. f47ac10b-58cc-4372-a567-0e02b2c3d479.

一个版本4的UUID由122显著位,给2 ^ 122不同的值是一个的非常的大量。给定一组的 ^ h 的值,值的预期数量,我们有如下发现有50%的机会在第一随机碰撞之前选择可以计算(见的生日攻击维基百科):

A version 4 UUID consist of 122 significant bits, giving 2^122 distinct values which is a very large number. Given a set of H values, the expected number of values we have to choose before finding the first random collision with a 50% chance can be calculated as follows (see Birthday Attack on Wikipedia):

结果(生日方向)2 ^ 122不同的价值大约是2,89e + 18。这假定所生成的值随机分布。显然,如果值分布不均匀,随机碰撞可以找到更快。有关详细信息参见<一href="http://en.wikipedia.org/wiki/Universally_Unique_Identifier#Random_UUID_probability_of_duplicates"相对=nofollow> 重复<随机UUID概率/ em>的。

The result (birthday bound) for 2^122 different values is approximately 2,89e+18. This assumes that the generated values are randomly distributed. Obviously, if the values are distributed unevenly, a random collision can be found faster. For further details also see Random UUID probability of duplicates.

1 <子>作为事实上,Melissa蠕虫病毒的作者可能是的追查由于GUID生成使用一个版本1算法。

1As a matter of fact, the author of the Melissa worm could be tracked down due to a GUID generated using a version 1 algorithm.

这篇关于如何.NET 4的GUID产生的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆