title: Convert HMAC-SHA384 function from Java to JavaScript
body: <p>This is the java function that does the job.</p>
  
  <pre><code> static byte[] HmacSHA384(String data, byte[] key) {
      try {
          mac.init(new SecretKeySpec(key, HMAC_ALGORITHM));
      } catch (InvalidKeyException e) {
          //throw new PWAINUnRecoverableException("Invalid key exception while mac init", e);
          throw new RuntimeException("Invalid key exception while mac init", e);
      }
      return mac.doFinal(data.getBytes(StandardCharsets.UTF_8));
  }
  </code></pre>
  
  <p>I've already tried <a href="https://stackoverflow.com/questions/7480158/how-do-i-use-node-js-crypto-to-create-a-hmac-sha1-hash">this answer</a> with no luck.</p>
  
  <p>Used <code>crypto-js</code> module also as:</p>
  
  <pre><code>const result = crypto_js.HmacSHA384(key, data).toString();
  console.log(result.split('').map(getBytes)); // used this to match byte array from java output. No luck!
  </code></pre>
  
  <pre><code>function getBytes(x) {return x.charCodeAt(0);}
  </code></pre>
  
  <p>Note that I'm using <code>key</code> as a String in JavaScript code as <code>crypto_js.HmacSHA384</code> accepts String only and not a <code>byte[]</code>. But I've compared my string's <code>byte[]</code> with java code's <code>byte[]</code>.</p>
  
  <p>Output from JS code:</p>
  
  <pre><code>[97,104,69,80,106,49,121,83,100,87,120,56,76,65,101,71,54,52,81,110,104,108,72,55,54,56,112,104,56,109,72,101,68,43,83,70,73,89,54,81,71,53,49,98,48,119,115,117,72,83,112,117,99,110,107,76,113,78,105,73,76,107,120,82]
  </code></pre>
  
  <p>Output from Java code:</p>
  
  <pre><code>[-29, 76, -16, -110, -35, -87, 18, -53, -1, -105, -77, -96, -49, -110, 102, -74, -110, 31, -87, 115, 102, -43, 101, -89, -82, -8, 96, -99, -89, 103, -128, 104, -121, -107, -98, 18, -18, 85, 97, -121, 30, 91, -42, -11, -6, -58, -7, 113]
  </code></pre>
  
  <p>Both takes same input.</p>
  
  <p>Any help will be appreciated. Thanks!</p>