HMAC POST API-Anforderungsvalidierung Android ELS
Posted: 17 Jan 2025, 08:20
Ich versuche, meine Nutzlast mithilfe der HMAC-Methode zu validieren, wie im Link unten beschrieben.
https://developers.google.com/android/e ... _code_hmac
Ich habe das hier erwähnte Beispiel zur Validierung verwendet:
https://developers.google.com/android/e ... examples_2
Ich habe Nodejs zur Validierung verwendet, erhalte jedoch nicht die richtige Ausgabe. Das Nodejs-Codebeispiel finden Sie unten:
Kann mir jemand bei dem möglichen Problem der Nichtübereinstimmung helfen?
https://developers.google.com/android/e ... _code_hmac
Ich habe das hier erwähnte Beispiel zur Validierung verwendet:
https://developers.google.com/android/e ... examples_2
Ich habe Nodejs zur Validierung verwendet, erhalte jedoch nicht die richtige Ausgabe. Das Nodejs-Codebeispiel finden Sie unten:
Code: Select all
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