# Decode base64 to value

**URL:** <https://discourse.nodered.org/t/decode-base64-to-value/51829>\
**Category:** General\
**Created:** [4 October 2021 11:35 UTC](https://discourse.nodered.org/t/decode-base64-to-value/51829 "2021-10-04T11:35:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ketpa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ketpa/32/42496_2.png) [@ketpa](https://discourse.nodered.org/u/ketpa)\
**Post date:** [4 October 2021 11:35 UTC](https://discourse.nodered.org/t/decode-base64-to-value/51829/1 "2021-10-04T11:35:04Z")

</div>

I have payload encoded in base64  
payload = jwSPBI8EkASQBJAEkASOBI4EjgSOBI8EjwSPBJEEkQSSBJIEkwSTBJQElASVBJUElgSWBJcElwSYBJkE  
or payload = PAAAelFhAAAABwEBMgAAAAAAAQBMBOIEAAAAAAAAPADWK+sVgACCQgAADQCAAIJCHJNHYQAAAAAAAAAAAQBdAQ==

and this describe

 ![obraz](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7f23b069395bba88047ec8a66af7847c9bded543.png)  
 ![obraz](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/2/f2850ca17e980b6fe0e0e0730ef9e894d5f6a754.png)

How to decode that in node-red ?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [4 October 2021 13:55 UTC](https://discourse.nodered.org/t/decode-base64-to-value/51829/2 "2021-10-04T13:55:43Z")

</div>

You can use a change node and JSONata expression set to `$base64decode(payload)`  
Or there is a Base64 contrib node.

> **[node-red-node-base64](https://flows.nodered.org/node/node-red-node-base64)**
>
> A Node-RED node to pack and unpack objects to base64 format

example

```auto
[{"id":"3fd3fa3f.9e49b6","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"PAAAelFhAAAABwEBMgAAAAAAAQBMBOIEAAAAAAAAPADWK+sVgACCQgAADQCAAIJCHJNHYQAAAAAAAAAAAQBdAQ==","payloadType":"str","x":120,"y":4560,"wires":[["cd62cb00.fe0e28","f902ba.890ccd48"]]},{"id":"cd62cb00.fe0e28","type":"change","z":"b779de97.b1b46","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$base64decode($$.payload)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":4560,"wires":[["37ca434a.148d5c"]]},{"id":"f902ba.890ccd48","type":"base64","z":"b779de97.b1b46","name":"","action":"b64","property":"payload","x":350,"y":4520,"wires":[["37ca434a.148d5c"]]},{"id":"37ca434a.148d5c","type":"debug","z":"b779de97.b1b46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":580,"y":4560,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![ketpa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ketpa/32/42496_2.png) [@ketpa](https://discourse.nodered.org/u/ketpa)\
**Post date:** [5 October 2021 07:27 UTC](https://discourse.nodered.org/t/decode-base64-to-value/51829/3 "2021-10-05T07:27:50Z")

</div>

I try it, but i have a string. How to to this ![obraz](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/ed90e5933ba839a37ccbb67d262cc625876938ff.png)

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [5 October 2021 09:28 UTC](https://discourse.nodered.org/t/decode-base64-to-value/51829/4 "2021-10-05T09:28:44Z")

</div>

Once you have the byte array (buffer) that will be output by the base64 node you will need to use a different node to parse that into it's respective fields.

Most likely something like

> **[node-red-contrib-binary](https://flows.nodered.org/node/node-red-contrib-binary)**
>
> A Node-RED node to parse and serialize binary data

---

<div class="post-metadata">

**Author:** ![ketpa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ketpa/32/42496_2.png) [@ketpa](https://discourse.nodered.org/u/ketpa)\
**Post date:** [5 October 2021 11:43 UTC](https://discourse.nodered.org/t/decode-base64-to-value/51829/5 "2021-10-05T11:43:39Z")

</div>

I have something like this:

```auto
[{"id":"6ca2bf9c.c9fe2","type":"inject","z":"15ff44a1.77852b","name":"prop trz","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"PAAAelFhAAAABwEBBQAAAAAAAQBMBOIEAAAAAAAAPAAqWZUsgACCQgAADQCAAIJCHJNHYQAAAAAAAAAAAQBdAQ==","payloadType":"str","x":110,"y":2720,"wires":[["da404f4.fafe53"]]},{"id":"829edb74.f7c06","type":"binary","z":"15ff44a1.77852b","name":"","property":"payload","pattern":"l64=>data,l16=>value","x":430,"y":2720,"wires":[["3d6620a0.5b02c"]]},{"id":"3d6620a0.5b02c","type":"debug","z":"15ff44a1.77852b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":2720,"wires":[]},{"id":"da404f4.fafe53","type":"base64","z":"15ff44a1.77852b","name":"","action":"","property":"payload","x":260,"y":2720,"wires":[["829edb74.f7c06"]]}]

```

 ![obraz](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bdc2529dd69ad1e8f6b5b8e5a4d5729a0305271f.png)  
 ![obraz](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/d/3d3c41125b57fde46014e9089bfdc31f0672f2d5.png)  
 ![obraz](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/57d564c235049b01abe15c83833151446281cda6.png)

payload: PAAAelFhAAAABwEBBQAAAAAAAQBMBOIEAAAAAAAAPAAqWZUsgACCQgAADQCAAIJCHJNHYQAAAAAAAAAAAQBdAQ==  
whats wrong?

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [5 October 2021 12:05 UTC](https://discourse.nodered.org/t/decode-base64-to-value/51829/6 "2021-10-05T12:05:21Z")

</div>

We can't really answer that, we don't have enough information.

The snippet of the spec sheet you've included only talks about 10 bytes, but the base64 string you've supplied has 64 bytes and the other example in the first post has 60.

There may be more leading padding in the input message, or they may hold totally different data.

---

<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:** [4 December 2021 12:05 UTC](https://discourse.nodered.org/t/decode-base64-to-value/51829/7 "2021-12-04T12:05:46Z")

</div>

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