# Ascon.js (decryption for ascon)

**URL:** <https://discourse.nodered.org/t/ascon-js-decryption-for-ascon/97598>\
**Category:** Dashboard\
**Tags:** node-red-dashboard, docker, function-node, flows\
**Created:** [13 June 2025 04:14 UTC](https://discourse.nodered.org/t/ascon-js-decryption-for-ascon/97598 "2025-06-13T04:14:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![maulanamuslih](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maulanamuslih/32/101417_2.png) [@maulanamuslih](https://discourse.nodered.org/u/maulanamuslih)\
**Post date:** [13 June 2025 04:14 UTC](https://discourse.nodered.org/t/ascon-js-decryption-for-ascon/97598/1 "2025-06-13T04:14:05Z")

</div>

Is there anyone here who knows how to decrypt ascon on Node-RED Docker Desktop? I tried looking in the node palette but there is no ascon.js. I am trying to decrypt ascon on the Node-RED side using Docker Desktop.

 ![pokopkop](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/0/90d2c92a903163319b0be0ce56dc2a444e6965f3.png)  
 ![asdasada](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/1/c1c6da13180d3363c01e6b960133a324324c095b.png)

---

<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:** [13 June 2025 06:00 UTC](https://discourse.nodered.org/t/ascon-js-decryption-for-ascon/97598/2 "2025-06-13T06:00:47Z")

</div>

You can import libs in a function node - see: [Use any npm module in Node-RED • FlowFuse](https://flowfuse.com/blog/2023/06/import-modules/)

Demo:

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

Demo flow (use `CTRL+I` to import)

```auto
[{"id":"da6c913bd723cbac","type":"function","z":"a56117c9f31908fc","name":"Encrypt Payload","func":"\nconst { key, nonce, associatedData } = msg\nconst plaintext = msg.payload\n\n// Ensure all required fields are provided\nif (!plaintext || !key || !nonce || !associatedData) {\n node.error('Missing required fields: payload, associatedData, ciphertext, key, nonce')\n return null\n}\n\ntry {\n const encrypted = JsAscon.encrypt(key, nonce, associatedData, plaintext)\n msg.encrypted = encrypted\n msg.payload = Buffer.from(encrypted).toString()\n\n // node.warn({key, nonce, associatedData, encrypted});\n // const decrypted = JsAscon.decrypt(key, nonce, associatedData, encrypted)\n // msg.decrypted = Buffer.from(decrypted).toString()\n return msg\n} catch (error) {\n node.error('Encryption failed: ' + error.message)\n return null\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"JsAscon","module":"js-ascon"}],"x":1620,"y":120,"wires":[["5ce4d504f7baa593","3d896c5149b5cf9d"]]},{"id":"4a550a6826a7fa9c","type":"inject","z":"a56117c9f31908fc","name":"","props":[{"p":"key","v":"[32,117,219,188,84,65,45,141,195,177,115,35,86,210,103,131]","vt":"json"},{"p":"nonce","v":"[218,218,140,157,63,244,20,146,142,39,7,30,39,249,220,102]","vt":"json"},{"p":"associatedData","v":"Some data 😋 文 This data is not contained in the encrypt output. You must pass the same data to encrypt and decrypt in order to be able to decrypt the message.","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"plain text","payloadType":"str","x":1620,"y":60,"wires":[["da6c913bd723cbac"]]},{"id":"5ce4d504f7baa593","type":"debug","z":"a56117c9f31908fc","name":"encrypted","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"msg","x":1660,"y":160,"wires":[]},{"id":"3d896c5149b5cf9d","type":"function","z":"a56117c9f31908fc","name":"Decrypt Payload","func":"\nconst { key, nonce, associatedData } = msg\n// const encryptedData = Buffer.from(msg.payload) // not working\nconst encryptedData = msg.encrypted\n\n// Ensure all required fields are provided\nif (!encryptedData || !key || !nonce) {\n node.error('Missing required field: payload, key, nonce')\n return null\n}\n\ntry {\n const decrypted = JsAscon.decrypt(key, nonce, associatedData, encryptedData)\n msg.payload = Buffer.from(decrypted).toString()\n return msg\n} catch (error) {\n node.error('Decryption failed: ' + error.message)\n return null\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"JsAscon","module":"js-ascon"}],"x":1840,"y":120,"wires":[["3fb87d5488596fb0"]]},{"id":"3fb87d5488596fb0","type":"debug","z":"a56117c9f31908fc","name":"decrypted","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1920,"y":160,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [13 June 2025 06:00 UTC](https://discourse.nodered.org/t/ascon-js-decryption-for-ascon/97598/3 "2025-06-13T06:00:50Z")

</div>

What is the contents of your function node ? Perhaps you should import it first on the 'setup' tab.

---

<div class="post-metadata">

**Author:** ![maulanamuslih](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maulanamuslih/32/101417_2.png) [@maulanamuslih](https://discourse.nodered.org/u/maulanamuslih)\
**Post date:** [13 June 2025 06:23 UTC](https://discourse.nodered.org/t/ascon-js-decryption-for-ascon/97598/4 "2025-06-13T06:23:21Z")

</div>

Thank you, you are right, but I still cannot fully decrypt it into purely JSON 🙂  
i believe this still refers to the function node.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [13 June 2025 06:25 UTC](https://discourse.nodered.org/t/ascon-js-decryption-for-ascon/97598/5 "2025-06-13T06:25:16Z")

</div>

Previously:

> What is the contents of your function node ?

This is important - how do you instanciate the function.

---

<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:** [13 June 2025 06:27 UTC](https://discourse.nodered.org/t/ascon-js-decryption-for-ascon/97598/6 "2025-06-13T06:27:08Z")

</div>

Did you try the fully working self contained demo I posted above?

---

<div class="post-metadata">

**Author:** ![maulanamuslih](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maulanamuslih/32/101417_2.png) [@maulanamuslih](https://discourse.nodered.org/u/maulanamuslih)\
**Post date:** [13 June 2025 07:30 UTC](https://discourse.nodered.org/t/ascon-js-decryption-for-ascon/97598/7 "2025-06-13T07:30:49Z")

</div>

PROBLEM SOLVED GUYS! Thanks for help me.

---

<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:** [27 June 2025 07:31 UTC](https://discourse.nodered.org/t/ascon-js-decryption-for-ascon/97598/8 "2025-06-27T07:31:41Z")

</div>

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