How to use node module "crypto" correctly?

i want to calc a hmac with md5.

crypto-js is not longer maintained. crypto-js - npm

Is it possible to use node:crypto in a function node?
https://nodejs.org/docs/latest-v20.x/api/crypto.html#class-hmac

Am i overthinking or missing something?

const text = 'I love cupcakes'
const key = 'abcdeg'

const gen_hmac = crypto.createHmac('md5', key)
    .update(text)
    .digest('hex')
msg.payload = gen_hmac
return msg;
[{"id":"9fcd0d88c89ef781","type":"function","z":"02f9e197120dd932","name":"hmac","func":"const text = 'I love cupcakes'\nconst key = 'abcdeg'\n\n\nconst gen_hmac = crypto.createHmac('md5', key)\n    .update(text)\n    .digest('hex')\nmsg.payload = gen_hmac\nreturn msg;","outputs":1,"timeout":0,"noerr":1,"initialize":"","finalize":"","libs":[],"x":850,"y":260,"wires":[["456c3c15f6eccc6f"]]},{"id":"c91edeaad15ab4ac","type":"inject","z":"02f9e197120dd932","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":680,"y":260,"wires":[["9fcd0d88c89ef781"]]},{"id":"456c3c15f6eccc6f","type":"debug","z":"02f9e197120dd932","name":"debug 448","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1070,"y":260,"wires":[]}]

Yes.

Just add it to the setup tab.

image

1 Like

lol, i was just to stupid... need more coffee. Thanks!

1 Like

openssl version, if someone want to use this in an exec node:

echo -n "I love cupcakes" | openssl dgst -md5 -hmac "abcdeg" "$@" | awk '{print $2}'

grafik


[{"id":"f1dd97b244c049de","type":"exec","z":"02f9e197120dd932","command":"echo -n \"I love cupcakes\" | openssl dgst -md5 -hmac \"abcdeg\" \"$@\" | awk '{print $2}'","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"openssl","x":700,"y":360,"wires":[["44703693989380fe"],[],[]]},{"id":"98c7f1cbf9c6c6c9","type":"inject","z":"02f9e197120dd932","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":520,"y":360,"wires":[["f1dd97b244c049de"]]},{"id":"44703693989380fe","type":"debug","z":"02f9e197120dd932","name":"debug 449","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":360,"wires":[]}]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.