JDK使用什么命名空间来生成名称为UUIDFromBytes的UUID? [英] What namespace does the JDK use to generate a UUID with nameUUIDFromBytes?

查看:171
本文介绍了JDK使用什么命名空间来生成名称为UUIDFromBytes的UUID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sun / Oracle JDK公开了一个函数,用于在java.util包中创建类型3(基于名称)的UUID:java.util.UUID.nameUUIDFromBytes(byte [] name)。

The Sun/Oracle JDK exposes a function to create a type 3 (name based) UUID in the java.util package: java.util.UUID.nameUUIDFromBytes(byte[] name).

我需要能够使用nameUUIDFromBytes在Java中生成类型3 UUID,并在使用其他语言创建类型3 UUID时获得相同的UUID,假设我提供与源相同的字节。

I need to be able to generate a type 3 UUID in Java using nameUUIDFromBytes and arrive at the same UUID when creating a type 3 UUID in another language, assuming I provide the same bytes as the source.

根据javadocs,此函数创建符合RFC 4122的类型3 UUID。但是,根据 RFC 4122 规范,必须在某个名称空间内创建类型3 UUID 。大多数其他语言允许您在创建类型3 UUID时指定命名空间(例如Ruby中的 UUIDTools gem )。

According to the javadocs this function creates a RFC 4122 compliant type 3 UUID. However, according to the RFC 4122 spec, a type 3 UUID must be created within some namespace. Most other languages allow you specify the namespace when creating a type 3 UUID (e.g. the UUIDTools gem in Ruby).

所以我的问题是:当我调用nameUUIDFromBytes时,JDK使用了什么命名空间UUID?

So my question is: what namespace UUID is used by the JDK when I invoke nameUUIDFromBytes?

推荐答案

参见此错误报告

特别是评论,靠近底部:

Especially the comment, near the bottom:

也许此时的操作过程是修复javadoc,声明
nameUUIDFromBytes(byte [] namespaceAndName)应该传入包含串联的字节数组的字节数组命名空间UUID的字节和名称字节(按此顺序)这假设方法只是MD5的字节[]并根据IETF文档设置字段。

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进行比较。

I don't know if i trust this to work correctly, but it should be easy to test using the predefined namespeces from the UUID spec, comparing with same UUID generated by some other implementation.

这篇关于JDK使用什么命名空间来生成名称为UUIDFromBytes的UUID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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