手动更改GUID-有多严重? [英] Manual change of GUID - how bad is it?

查看:1029
本文介绍了手动更改GUID-有多严重?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

手动更改和使用生成的GUID有多严重?碰撞的可能性仍然微不足道吗?还是使用GUID进行危险操作?

How bad is changing generated GUID manually and using it? Is the probability of collision still insignificant or is manipulation with GUIDs dangerous?

有时,我们只是更改先前生成的GUID的一部分字母并使用它即可.我们应该停止这样做吗?

Sometimes we just change some letter of previously generated GUID and use it. Should we stop doing it?

推荐答案

这取决于GUID的版本以及进行更改的位置.让我们剖析一下GUID的实际外观:

This depends on the version of the GUID and where you are making the change. Let's dissect a little how a GUID actually looks like:

  1. GUID具有版本.  GUID中的第13个十六进制数字标记其版本.当前的GUID通常是使用版本4生成的.如果向后更改版本,则可能会与已经存在的GUID发生冲突.向前更改它,可能会与将来的潜在GUID发生冲突.

  1. A GUID has a version.   The 13th hex digit in a GUID marks its version. Current GUIDs are usually generated with version 4. If you change the version backwards you risk collision with a GUID that already exists. Change it forwards and you risk collision with potential future GUIDs.

GUID也具有变体.  GUID中的第17个十六进制数字是变量字段.其中一些值保留用于向后兼容,一个值保留用于将来扩展.因此,在此更改某些内容意味着您可能会与先前生成的GUID或将来可能会生成的GUID发生冲突.

A GUID has a variant too.   The 17th hex digit in a GUID is the variant field. Some values of it are reserved for backward compatibility, one value is reserved for future expansion. So changing something there means you risk collision with previously-generated GUIDs or maybe GUIDs to be generated in the future.

GUID的结构因版本而异. 版本4 GUID使用(在大多数情况下-第17个十六进制数字除外)真正的随机或伪随机位(在大多数实现中为伪随机).在此进行更改,您发生碰撞的可能性几乎保持不变.

A GUID is structured differently depending on the version.   Version 4 GUIDs use (for the most part – excepting the 17th hex digit) truly random or pseudo-random bits (in most implementation pseuso-random). Change something there and your probability of collision remains about the same.

对于使用散列的版本3和5 GUID,它应该非常相似,尽管我不记得曾经在野外看到过一个.不过,版本1和版本2并没有太多.它们具有结构,根据您在哪里更改某些内容,您会使事情变得困难.

It should be very similar for version 3 and 5 GUIDs which use hashes, although I don't recall ever seeing one in the wild. Not so much for versions 1 and 2, though. Those have a structure and depending on where you change something you make things difficult.

版本1 GUID包含时间戳记和一个计数器字段,如果在相同的时钟间隔内生成两个GUID,则该计数器字段将递增(从而导致相同的时间戳记).如果更改时间戳,则可能会与同一台计算机上先前或之后生成的GUID发生冲突.如果您更改计数器,则可能会与同时生成的GUID发生冲突,因此需要将该计数器作为唯一符".

Version 1 GUIDs include a timestamp and a counter field which gets incremented if two GUIDs are generated in the same clock interval (and thus would lead to the same timestamp). If you change the timestamp you risk colliding with a GUID generated earlier or later on the same machine. If you change the counter you risk colliding with a GUID that was generated at the same time and thus needed the counter as a "uniquifier".

版本2 GUID在版本1上进行了扩展,并且还包含用户ID. 时间戳记的准确性较低,并且包含用户或组ID,而计数器的一部分则用于指示是哪一个(但是,这仅对生成器有意义).因此,如果更改这些零件,则有可能与另一名用户在同一台​​计算机上生成的GUID相冲突.

Version 2 GUIDs expand on version 1 and include a user ID as well.   The timestamp is less accurate and contains a user or group ID while a part of the counter is used to indicate which one is meant (but which only has a meaning to the generating machine). So with a change in those parts you risk collision with GUIDs generated by another user on the same machine.

版本1和2 GUID包含MAC地址. 具体来说,就是生成它们的计算机的MAC地址.这样可以确保即使在同一瞬间生成的来自不同计算机的GUID也不同.如果一台机器没有MAC地址,但是没有唯一性保证,则存在一个回退. MAC地址也具有结构,并且由组织唯一标识符"(OUI;可以由本地管理或由IEEE分发)和网卡的唯一标识符组成.

Version 1 and 2 GUIDs include a MAC address.   Specifically, the MAC address of the computer that generated them. This ensures that GUIDs from different machines are different even if generated in the very same instant. There is a fallback if a machine doesn't have a MAC address but then there is no uniqueness guarantee. A MAC address also has a structure and consists of an "Organisationally Unique Identifier" (OUI; which is either locally-administered or handed out by the IEEE) and an unique identifier for the network card.

如果在OUI中进行更改,则可能会与其他制造商的网卡计算机上生成的GUID发生冲突.除非您进行更改,否则第一个八位位组的第二个最低有效位为1,在这种情况下,您将切换到本地管理的OUI,并且仅可能与在具有被覆盖的MAC地址的计算机上生成的GUID发生冲突(这可能会包括大多数具有虚拟网络硬件的VM).

If you make a change in the OUI you risk colliding with GUIDs generated in computers with network cards of other manufacturers. Unless you make the change so the second-least significant bit of the first octet is 1, in which case you're switching to a locally-administered OUI and only risk collision with GUIDs generated on computers that have an overridden MAC address (which might include most VMs with virtual network hardware).

如果碰巧有卡标识符,则可能会与由同一制造商在具有其他网卡的计算机上生成的GUID发生冲突,或者再次与那些MAC地址被覆盖的GUID发生冲突.

If you chance the card identifier you risk collision with GUIDs generated on computers with other network cards by the same manufacturer or, again, with those where the MAC address was overridden.

到目前为止,没有其他版本,但要旨如下: GUID需要其所有部分来确保唯一性;如果您更改了某些内容,则最终可能会得到一个GUID,而该GUID不再是唯一的.因此,您可能会将其更多地用作GID或其他内容.最安全的更改可能是当前的版本4 GUID(这是Windows和.NET生成的版本),因为它们并不能真正保证唯一性,而是使其非常非常不可能. em>.

No other versions exist so far but the gist is the following: A GUID needs all its parts to ensure uniqueness; if you change something you may end up with a GUID which isn't necessarily unique anymore. So you're probably making it more of a GID or something. The safest to change are probably the current version 4 GUIDs (which is what Windows and .NET will generate) as they don't really guarantee uniqueness but instead make it very, very unlikely.

通常来说,生成新的GUID要好得多.这也有助于阅读它们的人,因为如果两个GUID看起来完全不同,则可以轻松区分两个GUID.如果它们只是个位数不同,那么一个人很可能会错过更改并假定GUID是相同的.

Generally I'd say you're much better off generating a new GUID, though. This also helps the person reading them because you can tell two GUIDs apart as different easily if they look totally different. If they only differ in a single digit a person is likely to miss the change and assume the GUIDs to be the same.

进一步阅读:

  • Wikipedia: GUID
  • Wikipedia: UUID
  • Eric Lippert: GUID guide. Part 1, part 2, part 3. (Read it; this guy can explain wonderfully and happens to be on SO too)
  • Wikipedia: MAC address
  • RFC 4122: The GUID versions
  • RFC 4122: The variant field
  • DCE 1.1: Authentication and security services – The description of version 2 GUIDs
  • Raymond Chen: GUIDs are globally unique, but substrings of GUIDs aren't
  • Raymond Chen: GUIDs are designed to be unique, not random

这篇关于手动更改GUID-有多严重?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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