Código Python:
signature = hmac.new(bytearray.fromhex(key), data.encode('utf-8'), hashlib.sha256).hexdigest()Soluciones que he probado
var compute_hmac = crypto.createHmac('sha256', key).update(data).digest('hex'); var compute_hmac = crypto.createHmac('sha256', Buffer.from(key, 'hex').toString()).update(data).digest('hex'); const hmac = crypto.createHmac('sha256', Buffer.from(key, 'hex'))
Intentando validar las firmas de webhook de la siguiente API
https://developer.close.com/topics/webhooks/
data es la carga útil recibida, lo mismo se pasa a python y al código JS. Pero de alguna manera, el resumen hexadecimal del código python se valida y el código hexadecimal del código JS es completamente diferente.
Consulte el enlace API mencionado anteriormente (firmas de webhook) para comprender lo que estoy tratando de lograr
Pase directamente el búfer de teclas en lugar de agregarle .toString()
var compute_hmac = crypto.createHmac('sha256', Buffer.from(key, 'hex')).update(data).digest('hex');codigo py
import hashlib import hmac key ="A1FF92"; data = "hello" signature = hmac.new(bytearray.fromhex(key), data.encode('utf-8'), hashlib.sha256).hexdigest() //78a1151ddd4f298a134e4625362af2ab8ef4bd49719e17053ec1eadd4cbf1babcódigo de nodo
var crypto = require("crypto") var key = "A1FF92" var data="hello"; var compute_hmac = crypto.createHmac('sha256', Buffer.from(key, 'hex')).update(data).digest('hex'); // 78a1151ddd4f298a134e4625362af2ab8ef4bd49719e17053ec1eadd4cbf1bab