Crypto Module - Encrypt/Decrypt

Hi,
I need to be able to send an encrypted string to a third party (or store in an external master data service) and then when received through a webhook or API GET call to that service I need to be able to decrypt the string received to be able to use the original string in the workflow.

Have been trying with the crypto module but cant seem to get it to do what I want. Using n8n cloud.

Any help would be much appreciated
Thanks

1 Like

If you are running n8n as a docker container, launch it with next environment variable

NODE_FUNCTION_ALLOW_EXTERNAL=crypto

Let me know if it works.

1 Like

This will not work because he is using n8n cloud.

@pradilla Can you share the docs of the API you are trying to consume? Perhaps, I can help you out but need more details.

Oh, ok! :frowning:

In cloud currently it’s not posible to load external packages. However, this has been discussed and might be included in the future.

It sounds interesting @RicardoE105 :slight_smile:
Nice job guys!

1 Like

Thanks! Shared details on DM. Will post generic solution here later on so the community can benefit from this. :+1:

1 Like

The NodeJS Crypto Ciper and Deciper would solve the @pradilla 's problem and for sure would be an important security feature for all n8n and cloud users.

The NodeJS Crypto Ciper is based on AES standard allows that to encript and decript a string using a password and the number of bytes of the algorithm

This could be used to send sensitive body data to databases or other parties. The party need to know the password and the algorithm to decript the string.

Nice implementations of Crypto Ciper can be found in links above.

I found this can help to find a way to do it possible.

https://levelup.gitconnected.com/implementing-aes-encryption-in-node-js-and-c-from-scratch-6ee7b47ae6d4

The Crypto node uses the crypto library, so this functionality should not be difficult to add.

Hi @RicardoE105, hope all is well! While you are able to add this functionality to the crypto module is there any way you can think of to enable the external crypto calls inside the function module? @maxT any other idea?

Thanks!
Andres

Hi all :wave:

Happy to report that we have a ticket on n8n.cloud immediate backlog to expose various useful modules to be used in Function and Function Item nodes. Initially, these will be a shortlist of modules that n8n core is already utilizing (incl. lodash, moment.js, and now crypto).

We’ll get that launched as soon as we can. For context, adjusting the env vars is trivial but most of the effort will be auditing these libraries to ensure there are no security issues by exposing them to users.

Thanks!

@pradilla what max mentioned will allow you to to what @Miquel_Colomer suggested.

Nice news @RicardoE105 @maxT @pradilla
We essencially need to Encrypt and Decrypt … The options discussed above to implement an AES 256 iv sounds sutable ways.
The best approach you decide to handle will be more than welcome.
We will be here to help and to early test it.
:rocket:

Hi Max, hope all is well. Do you have an estimated date for these lib to be available to use in the function node?

Thanks!
Andres

Unfortunately I do not have a hard estimate at this time - will reach out directly to see what we can do.

For visibility, here’s what we’re doing on n8n.cloud to get crypto available faster:

Adding crypto was originally in a ticket with multiple other libs that required a security audit before being deployed. We’ve now moved crypto to it’s own ticket and moved it up the board - so should be out relatively soon.

Thanks!

1 Like