Sun/Oracle JDK 公开了一个在 java.util 包中创建类型 3(基于名称)UUID 的函数:java.util.UUID.nameUUIDFromBytes(byte[] name)。
我需要能够使用 nameUUIDFromBytes 在 Java 中生成类型 3 UUID,并在使用另一种语言创建类型 3 UUID 时获得相同的 UUID,假设我提供与源相同的字节。
根据 javadocs,此函数创建一个符合 RFC 4122 的类型 3 UUID。然而,根据RFC 4122规范,必须在某个 namespace 中创建类型 3 UUID。大多数其他语言允许您在创建类型 3 UUID 时指定命名空间(例如 Ruby 中的 UUIDTools gem)。
所以我的问题是:当我调用 nameUUIDFromBytes 时,JDK 使用什么命名空间 UUID?
最佳答案
尤其是底部附近的评论:
Perhaps the course of action at this point would be to fix the javadoc stating "nameUUIDFromBytes(byte[] namespaceAndName) "one should pass-in a byte array containing the concatenation of the namespace UUID's bytes and the name bytes (in that order)" That's assuming the method just MD5's the byte[] and sets the fields as per the IETF document.
我不知道我是否相信它能正常工作,但使用 UUID 规范中的预定义名称规范与其他实现生成的相同 UUID 进行比较应该很容易测试。
[编辑 2022-05-22:修复了指向工作中的 Java 错误数据库的链接,尽管新的错误数据库不包含以前数据库中的评论,尤其是此答案中引用的评论 <强>]强>
关于java - JDK 使用什么命名空间来生成名称为 UUIDFromBytes 的 UUID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9504519/