Sha1 on n8n cloud

Hi, so I was trying to use a sha1 crypto function in either crypto/function node, but since it’s not supported in the crypto node & n8n cloud can’t import custom npm functionality, I assume I would have to use the crypto function from somewhere else outside n8n then? Or is there an alternative that I’m not aware of? Thanks

Hey @lamela,
our Crypto node does support signing with SHA-1 using a private key. Is that what you were looking for?

1 Like

Hi @lamelama, the crypto module is one of the few available npm modules on n8n cloud. So if you, for example, want to calculate a SHA1 value based on a string, you could do something like this:

Just tested this on my own instance and it’s working fine:

1 Like

Thanks for the reply,but the function from the comment below is actually what I’m looking for. Just as a side note for some reason I couldn’t find the Alrogrith Name dropdown option the first time but once I saw your post & see that there’s supposed to be an option there I deleted the node and readded & it finally showed.

Yes this is exactly what I’m looking for initially I was looking to use separate npm module called sha1 which I couldn’t get to work.so this would work for me. Thank you

1 Like

Glad to hear this works for you, thanks so much for confirming!

Hello, Dear MutedJam!
When i try to use you sample, i have error: ERROR: Cannot find module ‘crypto’ [Line 1]
What can be wrong? Moreover, the crypto node works

Hi @yura, welcome to the community!

Are you using n8n cloud? If not, you’d need to make the crypto module available yourself using the NODE_FUNCTION_ALLOW_BUILTIN environment variable.

However, seeing the crypto node works I wouldn’t bother :wink:

1 Like

I am running self-hosted n8n and enabled the NODE_FUNCTION_ALLOW_BUILTIN=* in the docker config, but I still get: ERROR: Cannot find module ‘crypto’ [line 1]
VMError

VMError: Cannot find module 'crypto'
    at Resolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:126:9)
    at Resolver.resolve (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:121:15)
    at resolve (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/nodevm.js:317:21)
    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:485:11)
    at requireImpl (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/setup-node-sandbox.js:90:19)
    at require (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/setup-node-sandbox.js:171:10)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:1:113
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:8:2
    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:485:11)
    at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/nodevm.js:497:23)

Regarding the Crypto node, it seems to be missing HMAC SHA1 option, it only has SHA256 and higher. Any idea how to enable HMAC SHA1?

Hey @lazmo88,

You would need to configure n8n to have access to the crypto package in the code node, If you wanted to make a SHA1 hash you can use the hash('sha1') function after your string.

If you have set the env option set and it isn’t being picked up it could be that you restarted the container rather than doing a stop then a start.

Ok, stopping starting made the code node work, but I am uttrely lost with the code > crypto module.

Is there a reason why the native Crypto node does not support hmac sha1?

Here’s where I am at right now:

const crypto = require(“crypto”);

const key = ‘{{ $node[“Webhook”].json[“body”][“SecretKey”] }}’;
const data = ‘{{ $node[“Edit Fields”].json[“StringToSign”] }}’;

data1 = data.hash(‘sha1’,key).toString(‘base64’);

return data1;

What I am trying to achieve is to hash “data” (which is a string) and use provided key to apply hmac sha1 hashing and outputting result in base64 string.

Hey @lazmo88,

I am not sure why the Crypto node doesn’t have SHA1 I guess it could be where it is generally considered to be broken but we do still have MD5 as an option.

Ok, shame as it would be much faster than playing around with the Code node which seems to fail to output data no matter what. I removed all the crypto related functions and tried just to return a simple value from the previous node, it fails:

ERROR: Code doesn’t return items properly

Please return an array of objects, one for each item you would like to output.

Code: return $item(“0”).$node[“Edit Fields”].json[“body”][“secret”];

Edit: You need to always return array, not single values as it seems. Problem solved.

1 Like