1

I m trying to validate my payload using HMAC method as mentioned in the link below. https://developers.google.com/android/els/reference/http-spec#hash-based_message_authentication_code_hmac

I used the mentioned example for validation given here: https://developers.google.com/android/els/reference/http-spec#examples_2

I have used Nodejs for validation but I am not getting the correct output. The Nodejs code example is provided below:

const crypto = require('crypto');

// HMAC secret key (decoded from base64)
const HMAC_KEY = Buffer.from('ASNFZ4mrze8BI0VniavN7wEjRWeJq83vASNFZ4mrze8BI0VniavN7wEjRWeJq83vASNFZ4mrze8BI0VniavN7w==', 'base64');

// Function to compute HMAC 
function computeHmac(payload) {
  return crypto.createHmac('sha1', HMAC_KEY)
    .update(payload,'utf8') // Process the payload as a UTF-8 string
    .digest('hex'); // Output as a hexadecimal string
}

// Input
const payload = 'v=2&thunderbird_version=1&emergency_number=911';
const computedHmac = computeHmac(payload);
console.log('Computed HMAC:', computedHmac);

//Expected Output: e27dce749babe97c1188cf3e272b0492d018e8

//Actual output: 87d3197707630e01834de124cbff28bac274ff0c

Can anyone help me with the possible issue of the mismatch?

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.