# Convert node.js into node-red

**URL:** <https://discourse.nodered.org/t/convert-node-js-into-node-red/96597>\
**Category:** General\
**Tags:** function-node\
**Created:** [16 April 2025 08:02 UTC](https://discourse.nodered.org/t/convert-node-js-into-node-red/96597 "2025-04-16T08:02:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcsjohnson](https://avatars.discourse-cdn.com/v4/letter/t/7ab992/32.png) [@tcsjohnson](https://discourse.nodered.org/u/tcsjohnson)\
**Post date:** [16 April 2025 08:02 UTC](https://discourse.nodered.org/t/convert-node-js-into-node-red/96597/1 "2025-04-16T08:02:41Z")

</div>

Hi All,

I have a node.js code which need to use in Node-red as below:

Example of DES decryption in javascript/node.js:

```auto
function decrypt(payload, key) {
        	var payloadstr = payload.toString();
        	var keyWords = cryptoJs.enc.Utf8.parse(key);
        	var ivWords = cryptoJs.enc.Utf8.parse(key);
   		var reb64 = cryptoJs.enc.Hex.parse(payloadstr);
   		var bytes = reb64.toString(cryptoJs.enc.Base64);
   		var decrypt = cryptoJs.DES.decrypt(bytes, keyWords, { iv: ivWords, padding: cryptoJs.pad.Pkcs7, mode: cryptoJs.mode.CBC});
   		return decrypt.toString(cryptoJs.enc.Utf8);
}

```

Which function i need to use after convert?

Thank you

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 April 2025 08:38 UTC](https://discourse.nodered.org/t/convert-node-js-into-node-red/96597/2 "2025-04-16T08:38:11Z")

</div>

> [@tcsjohnson](#):
>
> Which function i need to use after convert?

I don't understand the question, please explain in more detail. Have you already implemented that function in a Function node or is that what you are asking how to do?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [16 April 2025 08:52 UTC](https://discourse.nodered.org/t/convert-node-js-into-node-red/96597/3 "2025-04-16T08:52:36Z")

</div>

You can either implement the function in settings.js as a global context variable or you can (probably) implement it in a function node.

Either way, you will need to install whatever npm package that provides `cryptoJs`.

---

<div class="post-metadata">

**Author:** ![tcsjohnson](https://avatars.discourse-cdn.com/v4/letter/t/7ab992/32.png) [@tcsjohnson](https://discourse.nodered.org/u/tcsjohnson)\
**Post date:** [17 April 2025 07:15 UTC](https://discourse.nodered.org/t/convert-node-js-into-node-red/96597/4 "2025-04-17T07:15:02Z")

</div>

i have install the crytojs. then i use decrypt nodes and insert the secret key and select DES. but still unable to debug it.

---

<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:** [17 April 2025 08:12 UTC](https://discourse.nodered.org/t/convert-node-js-into-node-red/96597/5 "2025-04-17T08:12:37Z")

</div>

You could simply use an existing node: [node-red-contrib-crypto-js-dynamic (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-crypto-js-dynamic)

However, if it is your goal to learn how to implement somthing like this in node-red function then simply add a reference to [`crypto`](https://nodejs.org/docs/latest-v22.x/api/crypto.html) in the function setup like this: [Use any npm module in Node-RED • FlowFuse](https://flowfuse.com/blog/2023/06/import-modules/)

---

<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:** [16 June 2025 08:13 UTC](https://discourse.nodered.org/t/convert-node-js-into-node-red/96597/6 "2025-06-16T08:13:06Z")

</div>

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