creating HMAC in Nodejs with base64 encoded secret
<p>I'm trying to generate HMAC of a message. The algo for HMAC generation is SHA256. The issue is i have a base64 encoded key(shared secret). How can i decode this secret to get the required hmac</p>

<p>Sample code:</p>

<pre><code>var hmac = require('crypto').createHmac('SHA256', "SOME_BASE64_ENCODED_SHARED_SECRET").update("MESSAGE").digest('base64');
</code></pre>

<p>This hmac is sent to a java service. The way it does hmac generation is as follows:</p>

<pre><code>Mac mac = Mac.getInstance("HmacSha256");
SecretKey sharedKey = new SecretKeySpec(Base64.getDecoder().decode("SOME_BASE64_ENCODED_SHARED_SECRET"), "TlsPremasterSecret");
mac.init(sharedKey);
byte[] messageBytes = "MESSAGE".getBytes("UTF-8");
byte[] expectedHmac = mac.doFinal(messageBytes);
String hmac = Base64.getEncoder().encodeToString(expectedHmac));
</code></pre>

<p>Now, the HMACs generated by my nodejs code does not match with Java service code. How do i solve this problem?</p>