In python, to make a Type 5 UUID we can simply do:
import uuid
print uuid.uuid5(uuid.NAMESPACE_URL, 'my string')
Looking through the java documentation for java.util.UUID, I don't see how to do it. First off, type 5 isn't mentioned. They do have a Type 3, but the signature is:
nameUUIDFromBytes(byte[] name)
Static factory to retrieve a type 3 (name based) UUID based on the specified byte array.
How can we make a Type 5 UUID in Java?
You can implement it yourself by following the code proposed in https://stackoverflow.com/a/28776880/1452094. However this does require some fiddling since the j.u.UUID constructor takes longs.
As of
Java 8
the standard library does not seem to support type 5. But third party libraries like "Apache Commons Id" have UUID implementations that do support it.EDIT: Here is a fully functional implementation:
To verify it works I ran the following code:
This created the output:
Verified against the official python implementation: