I have a 3rd party application that I can't control that uses Java's UUID.nameUUIDFromBytes to create a string. I need to reproduce this function written in JS.
In OpenJDK's source I found this:
public static UUID nameUUIDFromBytes(byte[] name) {
MessageDigest md;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException nsae) {
throw new InternalError("MD5 not supported", nsae);
}
byte[] md5Bytes = md.digest(name);
md5Bytes[6] &= 0x0f; /* clear version */
md5Bytes[6] |= 0x30; /* set to version 3 */
md5Bytes[8] &= 0x3f; /* clear variant */
md5Bytes[8] |= 0x80; /* set to IETF variant */
return new UUID(md5Bytes);
}
For the life of me I can't figure it out, mostly because of how JS abstracts bytes.
TL;DR: I just need a js function that will produce the same string as UUID.nameUUIDFromBytes((VARIABLE).getBytes(Charsets.UTF_8)).toString().