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

**URL:** <https://discourse.nodered.org/t/node-red-crypto-js-encoding-doesnt-work/34703>\
**Category:** General\
**Created:** [23 October 2020 08:11 UTC](https://discourse.nodered.org/t/node-red-crypto-js-encoding-doesnt-work/34703 "2020-10-23T08:11:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![seeQuayah](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@seeQuayah](https://discourse.nodered.org/u/seeQuayah)\
**Post date:** [23 October 2020 08:11 UTC](https://discourse.nodered.org/t/node-red-crypto-js-encoding-doesnt-work/34703/1 "2020-10-23T08:11:34Z")

</div>

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:

```auto
[{"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?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [23 October 2020 09:07 UTC](https://discourse.nodered.org/t/node-red-crypto-js-encoding-doesnt-work/34703/2 "2020-10-23T09:07:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![seeQuayah](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@seeQuayah](https://discourse.nodered.org/u/seeQuayah)\
**Post date:** [23 October 2020 12:03 UTC](https://discourse.nodered.org/t/node-red-crypto-js-encoding-doesnt-work/34703/3 "2020-10-23T12:03:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [23 October 2020 12:59 UTC](https://discourse.nodered.org/t/node-red-crypto-js-encoding-doesnt-work/34703/4 "2020-10-23T12:59:16Z")

</div>

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

```auto
{"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](https://github.com/Drswith/node-red-contrib-crypto-js-plus))

---

<div class="post-metadata">

**Author:** ![seeQuayah](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@seeQuayah](https://discourse.nodered.org/u/seeQuayah)\
**Post date:** [23 October 2020 14:40 UTC](https://discourse.nodered.org/t/node-red-crypto-js-encoding-doesnt-work/34703/5 "2020-10-23T14:40:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 November 2020 14:40 UTC](https://discourse.nodered.org/t/node-red-crypto-js-encoding-doesnt-work/34703/6 "2020-11-06T14:40:40Z")

</div>

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