Decrypt with password not working on NodeJS (server-side)

Wappler Version : W4 B12
Operating System : Mac M1
Server Model: NodeJS
Database Type: MySQL
Hosting Type: AWS Docker

Expected behavior

What do you think should happen?

Using the decrypt formatter on NodeJS should decrypt a previously encrypted piece of data.

Actual behavior

What actually happens?

Using the following in a Set Value step

q_getnotes.notesdetails.decrypt(getmemberrefs.dbstring + 'fixedstring')

results in the following error in the browser

message: "data.split is not a function"
stack: "TypeError: data.split is not a function\n    at decrypt (/opt/node_app/lib/formatters/crypto.js:57:37)\n    at /opt/node_app/lib/core/parser.js:667:26\n    at parser (/opt/node_app/lib/core/parser.js:356:19)\n    at Object.parseValue (/opt/node_app/lib/core/parser.js:729:24)\n    at App.parse (/opt/node_app/lib/core/app.js:456:23)\n    at App.setvalue (/opt/node_app/lib/modules/core.js:132:26)\n    at App._exec (/opt/node_app/lib/core/app.js:435:57)\n    at App._exec (/opt/node_app/lib/core/app.js:406:28)\n    at processTicksAndRejections (internal/process/task_queues.js:97:5)\n    at async App.exec (/opt/node_app/lib/core/app.js:375:9)"
status: "500"

You only get that error when q_getnotes.notesdetails is not the encrypted data string.

Ah, hang on. These were originally encrypted using the PHP formatter for encrypt and I’m trying to move the project to NodeJS. Is there a difference between the encrypted data on each server model? I would have expected it to be the same…

Ben, if that’s not the case it would be great if you could start an independent thread with a list of incompatibilities with your findings where we can add to the list. People doing the jump will find it very useful.

It will also help the team if and when they add an automatic importer.

1 Like

It looks like it’s different:
String produced in PHP:

String produced in NodeJS:
Using the same password for encryption

It seems they use different algorithms

Other than the obvious missing Argon support, this, I think is the only incompatibility I’ve found so far. If more pop up, I will happily consolidate into a single list.

1 Like

Hi @patrick, is this something that can be aligned to PHP or do I have to find a custom workaround?

We are limited with what PHP and NodeJS provide, both use different Crypto libraries and can cause different implementations that are not compatible. We try to keep as much code compatible, but this is not always possible.

In the beginning we only released actions that would be available in all languages, that was not always optimal and we had in some languages that we had to make workarounds to make it work the same. We now try to use more specific language features, this also means that some actions are only for specific languages. We could try to get the same result in NodeJS as we get from PHP, but I think it is better to just optimize the code for the specific language and use it native features instead of trying to simulate an other language and producing slower code just to be compatible.


Thanks @patrick,
I’m trying to write a custom formatter for NodeJS to translate from the PHP version. It seems the key requirements differ so it’s proving far from straight forward. I have PHP projects that have existing encrypted data and wanted to move them over to NodeJS.

I might have to decrypt, write to another field (forcing the key length to be compatible with NodeJS) and then write a decrypt formatter for PHP and NodeJS to allow them both to work…

Can’t you just call a php endpoint that does that for you and returns the decrypted value to your node workflow and encrypt again?

Or build a nodejs custom module that executes php on the shell.

exec("php decrypt.php 'encrypted_param'")

Or if you feel adventurous:

1 Like

Possibly… I need to weigh up the options as both will be live concurrently as users beta test and users will need to be able to update and view the encrypted records in both. Ideally, I’d like something that I can run in either without a dependency on the other system.

1 Like

Just in case you were curious. I have gone with writing new formatters for both PHP and NodeJS that are compatible. They generally follow the same code as the existing crypto formatters with the main difference being forcing the key length requirement of NodeJS crypto (must be 32 bytes) and following the same pattern (from NodeJS) of full stop separated iv/data. This way I can continue to have users working on either while making the data available to view/update on either.