How to store a key to generate an Hmac using the Crypto node?

I need to generate an Hmac signature using a secret key that I’ve stored in a custom credential. The Crypto node has an Hmac function and takes as input the secret key value. So how do I get the key value from the credential store into the Secret field in the Crypto node???

There has to be the ability to store an Hmac secret securely in the credential store AND then use it to generate Hmac signatures.

How?

  • n8n version: 1.76.4
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system: Windows 10

Accessing the “hidden” part of a credential using any kind of expression would defeat the purpose of having separated credential items in the first place.

I have looked before (out of curiosity) to see if the builtin variables and functions had something like $credential, but it doesn’t. If it did, anyone writing a workflow could peek at keys and passwords using a Set / Edit Fields node, which wouldn’t be very secure.

What @hubschrauber said is correct. But I could see a new feature that allows you to store your secret in a credential entry and then let the node use that under the hood when running thr node.
As far as I know this isnt a feature yet. So would need to crrate a feature request if there isnt one already.

There appears to be an existing feature request for it. Only 3 votes so far (since 2021). Maybe it needs some new energy. The suggested workaround of using $env is only slightly better, but security through obscurity isn’t really a good answer. That still has the same exposure issues.

So what’s the alternative? Hard-code the Hmac secret key in the workflow and have it appear in all the execution logs?

Hmacs need a secret key. The node has a Secret property that you have to set to use it. Where’s that secret supposed to be stored?

I’m kinda surprised @BramKn didn’t mention this custom/community node (unless that was written by a totally different guy named Bram… I’m not 100% sure it’s him). It seems like a perfect candidate for adding this kind of feature.

Thanks for the link. However, the GitHub repo for that package gives a 404.

Custom notes can read credentials though, so a custom node could be made to securely read and create the signature.

Kind of like how the JWT node works, I’m surprised that’s not supported by the crypto node yet, seems like a no-brainer that keeping some of those fields private/secure will be a priority.

Someone forked my node and kept the readme :joy:
This is not my node. :sweat_smile:

2 Likes

Do you still give access to your original node?

It is publicly available. But it doesn’t do what you are asking for here. :grin:

Would I be able to build something myself similar to what your node is doing? Could you give me a link?

Here are the docs. As long as you’re so much familiar with JS/TS it’s not to bad

1 Like