Decode base64 to value

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

and this describe


How to decode that in node-red ?

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

example

[{"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":[]}]
1 Like

I try it, but i have a string. How to to this obraz

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

I have something like this:

[{"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

payload: PAAAelFhAAAABwEBBQAAAAAAAQBMBOIEAAAAAAAAPAAqWZUsgACCQgAADQCAAIJCHJNHYQAAAAAAAAAAAQBdAQ==
whats wrong?

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.