title: Java's UUID.nameUUIDFromBytes to written in JavaScript?
body: <p>I have a 3rd party application that I can't control that uses Java's <code>UUID.nameUUIDFromBytes</code> to create a string. I need to reproduce this function written in JS.</p>
  <p>In <a href="https://github.com/dmlloyd/openjdk/blob/28cf61ba0955833f75cf7ba2b80cf83c557300d5/src/java.base/share/classes/java/util/UUID.java#L167" rel="nofollow noreferrer">OpenJDK's source</a> I found this:</p>
  <pre><code>public static UUID nameUUIDFromBytes(byte[] name) {
      MessageDigest md;
      try {
          md = MessageDigest.getInstance(&quot;MD5&quot;);
      } catch (NoSuchAlgorithmException nsae) {
          throw new InternalError(&quot;MD5 not supported&quot;, nsae);
      }
      byte[] md5Bytes = md.digest(name);
      md5Bytes[6]  &amp;= 0x0f;  /* clear version        */
      md5Bytes[6]  |= 0x30;  /* set to version 3     */
      md5Bytes[8]  &amp;= 0x3f;  /* clear variant        */
      md5Bytes[8]  |= 0x80;  /* set to IETF variant  */
      return new UUID(md5Bytes);
  }
  </code></pre>
  <p>For the life of me I can't figure it out, mostly because of how JS abstracts bytes.</p>
  <p>TL;DR: I just need a js function that will produce the same string as <code>UUID.nameUUIDFromBytes((VARIABLE).getBytes(Charsets.UTF_8)).toString()</code>.</p>