Node-red-crypto-js encoding doesn't work

I want to create an HMAC of a string, then encode it in base64. For that, I installed node-red-contrib-crypto-js in the palette.

Here is what I have done:

[{"id":"2aec555f.d07e6a","type":"tab","label":"here","disabled":false,"info":""},{"id":"47573c5f.fdd6e4","type":"inject","z":"2aec555f.d07e6a","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"a\": 3, \"b\": 5}","payloadType":"json","x":310,"y":80,"wires":[["5fa3a276.ae6fcc"]]},{"id":"4e411311.dbecec","type":"debug","z":"2aec555f.d07e6a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1210,"y":240,"wires":[]},{"id":"72fc1e2a.3345f","type":"hmac","z":"2aec555f.d07e6a","name":"","algorithm":"HmacSHA256","key":"secret","x":550,"y":180,"wires":[["c3f2ca1c.889268","83896ac8.530f48"]]},{"id":"5fa3a276.ae6fcc","type":"json","z":"2aec555f.d07e6a","name":"","property":"payload","action":"str","pretty":false,"x":390,"y":160,"wires":[["72fc1e2a.3345f"]]},{"id":"1cde8689.66eb39","type":"encode","z":"2aec555f.d07e6a","name":"64","encode":"Base64","x":870,"y":240,"wires":[["4e411311.dbecec"]]},{"id":"c3f2ca1c.889268","type":"encode","z":"2aec555f.d07e6a","name":"utf","encode":"Utf8","x":710,"y":200,"wires":[["1cde8689.66eb39","3175a0ac.8bde2"]]},{"id":"83896ac8.530f48","type":"debug","z":"2aec555f.d07e6a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":840,"y":120,"wires":[]},{"id":"3175a0ac.8bde2","type":"debug","z":"2aec555f.d07e6a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1050,"y":160,"wires":[]}]

The HMAC is correctly created but when I encode it in utf 8, it gives me an empty string. Why???

  • the encode in base64 node doesn't take a string as an input, it wants an utf8 encoded string. But as I said, the utf8 encoded string is empty. What can I do?

seeing how that node hasn't been updated in over 3 years, you might want to try node-red-contrib-crypto-js-plus which is a fork and is actively maintained.

Same thing is happening with crypto-js-plus, empty string after encoding

Yup there seems to be a bug. If you put in a catch node you will see the following:

{"message":"TypeError: wordArray.clamp is not a function","source":{"id":"8baaad02.deef18","type":"encode","name":"64","count":1},"stack":"TypeError: wordArray.clamp is not a function
    at Object.stringify (/Users/Paul/.node-red/node_modules/crypto-js/enc-base64.js:47:24)\n    at EncodeNode._inputCallback (/Users/Paul/.node-red/node_modules/node-red-contrib-crypto-js/cryptojs/encode.js:21:46)
    at EncodeNode.Node._emitInput (/usr/local/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:200:18)
    at Immediate._onImmediate (/usr/local/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:179:33)
    at processImmediate (internal/timers.js:439:21)"}

You should open an issue with the nodes author in GitHub (https://github.com/Drswith/node-red-contrib-crypto-js-plus)

I discovered what was wrong, you need to use the "decode (utf8)" node before the encode node, it will create a wordArray and then you can put encode node. This problem is solved but I can't do what I want with these nodes unfortunately.
Thanks for replying anyway

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