# Using SHA or MD5 inside function-node

**URL:** <https://discourse.nodered.org/t/using-sha-or-md5-inside-function-node/55040>\
**Category:** General\
**Tags:** function-node\
**Created:** [11 December 2021 13:00 UTC](https://discourse.nodered.org/t/using-sha-or-md5-inside-function-node/55040 "2021-12-11T13:00:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hutje](https://avatars.discourse-cdn.com/v4/letter/h/43a26b/32.png) [@hutje](https://discourse.nodered.org/u/hutje)\
**Post date:** [11 December 2021 13:00 UTC](https://discourse.nodered.org/t/using-sha-or-md5-inside-function-node/55040/1 "2021-12-11T13:00:49Z")

</div>

Is it possible to use the already existing crypto-js of Node-Red to use it inside the Function-node?  
Inside a for-loop I want to check if a part of a package is altered compared to my context-database. If so, I want to update that part. Because it happens inside a for-loop and only checks parts of an array, I want to use it inside my function-node and not outside with an external node.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 December 2021 15:33 UTC](https://discourse.nodered.org/t/using-sha-or-md5-inside-function-node/55040/2 "2021-12-11T15:33:09Z")

</div>

> [@hutje](#):
>
> Is it possible to use the already existing crypto-js of Node-Red to use it inside the Function-node

If you are using newer version of node-red, you can import the crypto library on the function node setup tab...

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/4/f459cb7e7ffb74531466e852863c50c7dc97171e.png)

![LA9BdyJ8y5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7fce7742444984855ce15df1339875a58cb9e29c.gif)

Demo Flow...

```auto
[{"id":"d3ad5e25c27b5344","type":"inject","z":"c6ecb8c5c651ca06","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"we love node-red","payloadType":"str","x":260,"y":140,"wires":[["4b9f5f72b1099bc1"]]},{"id":"4b9f5f72b1099bc1","type":"function","z":"c6ecb8c5c651ca06","name":"sha256","func":"msg.payload = crypto\n .createHash(\"sha256\")\n .update(msg.payload)\n .digest(\"hex\");\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"crypto","module":"crypto"}],"x":480,"y":140,"wires":[["bb173a2ab61486d3"]]},{"id":"ee9dd58b761ca1fb","type":"inject","z":"c6ecb8c5c651ca06","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Drink more coffee","payloadType":"str","x":260,"y":180,"wires":[["4b9f5f72b1099bc1"]]},{"id":"bb173a2ab61486d3","type":"debug","z":"c6ecb8c5c651ca06","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":700,"y":140,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![hutje](https://avatars.discourse-cdn.com/v4/letter/h/43a26b/32.png) [@hutje](https://discourse.nodered.org/u/hutje)\
**Post date:** [11 December 2021 15:56 UTC](https://discourse.nodered.org/t/using-sha-or-md5-inside-function-node/55040/3 "2021-12-11T15:56:23Z")

</div>

I have updated it, but I can't get the node version to update as well. I run Node-Red on a raspberry pi and use the script from [the website](https://nodered.org/docs/getting-started/raspberrypi) to update Node-Red. But with `--node14` I still get version 12.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 December 2021 16:07 UTC](https://discourse.nodered.org/t/using-sha-or-md5-inside-function-node/55040/4 "2021-12-11T16:07:22Z")

</div>

did you run the command correctly? ...

`bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) --node14`

Do you have `n` or `nvm` installed? These are often a cause of installation issues.

---

<div class="post-metadata">

**Author:** ![hutje](https://avatars.discourse-cdn.com/v4/letter/h/43a26b/32.png) [@hutje](https://discourse.nodered.org/u/hutje)\
**Post date:** [11 December 2021 16:12 UTC](https://discourse.nodered.org/t/using-sha-or-md5-inside-function-node/55040/5 "2021-12-11T16:12:23Z")

</div>

Not that I know of.  
Version Node.js: v12.22.7  
Version Npm: 6.14.15

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 December 2021 16:30 UTC](https://discourse.nodered.org/t/using-sha-or-md5-inside-function-node/55040/6 "2021-12-11T16:30:29Z")

</div>

> [@hutje](#):
>
> Not that I know of.

what do you get if you enter the following in the terminal...  
`which n`  
`which nvm`

Also, try running this script once more (as I wrote it above) and capture the output and log file - paste into reply as text (press the code `</>` button then paste log/output between the backticks)

---

<div class="post-metadata">

**Author:** ![hutje](https://avatars.discourse-cdn.com/v4/letter/h/43a26b/32.png) [@hutje](https://discourse.nodered.org/u/hutje)\
**Post date:** [11 December 2021 16:53 UTC](https://discourse.nodered.org/t/using-sha-or-md5-inside-function-node/55040/7 "2021-12-11T16:53:53Z")

</div>

For `which n` and `which nvm` I got nothing.  
No response just this:  
`pi@raspberrypi:~ $ which n`  
`pi@raspberrypi:~ $ which nvm`  
`pi@raspberrypi:~ $`

I tried to add the log by pressing `</>` but the size exceeded the limit.  
The log:  
[install log.log](https://discourse.nodered.org/uploads/short-url/7CRhUTIs3EYnHZZd81CCtx6ngDp.log) (74.3 KB)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 December 2021 17:27 UTC](https://discourse.nodered.org/t/using-sha-or-md5-inside-function-node/55040/8 "2021-12-11T17:27:48Z")

</div>

> [@hutje](#):
>
> For `which n` and `which nvm` I got nothing.

Ok, good.

I think your system needs updating. Can you do `sudo apt-get update` then `sudo apt-get upgrade`

Then remove node `sudo apt-get purge nodejs`

After that, run `sudo apt autoremove` then `sudo apt autoclean` to clean up any install files

Then try the script again as I posted above.

Please include a copy of the terminal this time.

---

<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:** [25 December 2021 17:28 UTC](https://discourse.nodered.org/t/using-sha-or-md5-inside-function-node/55040/9 "2021-12-25T17:28:38Z")

</div>

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