What namespace does the JDK use to generate a UUID with nameUUIDFromBytes?

前端 未结 2 799
耶瑟儿~
耶瑟儿~ 2020-12-29 10:34

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).

I need to be able

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 10:59

    See this bug report

    Especially the comment, near the bottom:

    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.

    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.

提交回复
热议问题