HMAC256 signature

Hey,

Any idea how to convert that python HMAC256 signature in N8N? I tried everything but keep getting an error “invalid signature”

I tried with Buffer and without Buffer. Same result…

PYTHON :

ts = int(time.time() * 1000)
request = Request('GET', '<api_endpoint>')
prepared = request.prepare()
signature_payload = f'{ts}{prepared.method}{prepared.path_url}'
signature_payload = signature_payload.encode()

hmac.new('YOUR_API_SECRET'.encode(), signature_payload, 'sha256').hexdigest()

N8N :

{
  "nodes": [
    {
      "parameters": {
        "action": "hmac",
        "type": "SHA256",
        "value": "={{ Buffer.from(String(Date.now()) + \"GET\" + \"/account\", \"hex\") }}",
        "dataPropertyName": "signature",
        "secret": "my_secret_key"
      },
      "name": "Crypto",
      "type": "n8n-nodes-base.crypto",
      "typeVersion": 1,
      "position": [
        730,
        440
      ]
    },
    {
      "parameters": {
        "url": "https://test.com/api/account",
        "options": {},
        "headerParametersUi": {
          "parameter": [
            {
              "name": "X-KEY",
              "value": "api_key"
            },
            {
              "name": "X-TS",
              "value": "={{Date.now()}}"
            },
            {
              "name": "X-SIGN",
              "value": "={{$json[\"signature\"]}}"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1120,
        440
      ]
    }
  ],
  "connections": {
    "Crypto": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Did you try the Crypto node?

As you can see in the sample I sent in my previous message, I already use it

Try the expression as follows: {{ "f"+ Date.now() + "GET" + "/account" }}

Uh, very sorry did not see that.