# Hash, Salt and beyond

**URL:** <https://discourse.nodered.org/t/hash-salt-and-beyond/60591>\
**Category:** General\
**Created:** [31 March 2022 13:16 UTC](https://discourse.nodered.org/t/hash-salt-and-beyond/60591 "2022-03-31T13:16:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [31 March 2022 13:16 UTC](https://discourse.nodered.org/t/hash-salt-and-beyond/60591/1 "2022-03-31T13:16:35Z")

</div>

Hi all!

I need to generate a Hash with these procedure:

1. The algorithm will be AES (that's not a problem).
2. Method AES/CBC/PKCS5PADDING
3. HASH in SHA-512

The first three points will be covered with a node.

But here comes the complex....additional the process will be the following:

1. The Salt will be dinamic and random.
2. Next to the Salt i need to apply a derivation process with a Hash 123WithHmac233
3. The point 2 needs to be returned in HEX or Base64

I found it difficult to do it in node red, specially the SALT part.

Thanks a lot in advance.

Regards!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [31 March 2022 18:57 UTC](https://discourse.nodered.org/t/hash-salt-and-beyond/60591/2 "2022-03-31T18:57:24Z")

</div>

What library are you using to do this? And what have you tried?

I'd use a suitable library and a function node myself.

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [31 March 2022 19:58 UTC](https://discourse.nodered.org/t/hash-salt-and-beyond/60591/3 "2022-03-31T19:58:11Z")

</div>

Hi.

I'cant use any library at all because i have to do it in a prod server, so no additional npm install can be done.

I know that the SALT is used in addition to the HASH and it can be placed in the first part or the last one of the HASH.

Tks!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [31 March 2022 21:48 UTC](https://discourse.nodered.org/t/hash-salt-and-beyond/60591/4 "2022-03-31T21:48:28Z")

</div>

Urm, you should never do crypto without a tried and trusted library. Rule number one: never do it yourself.

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [1 April 2022 18:03 UTC](https://discourse.nodered.org/t/hash-salt-and-beyond/60591/5 "2022-04-01T18:03:57Z")

</div>

Yes that is right.  
I know there is a well used library called 'cripto'.

Regards!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 April 2022 18:23 UTC](https://discourse.nodered.org/t/hash-salt-and-beyond/60591/6 "2022-04-01T18:23:16Z")

</div>

> [@Marty1982](#):
>
> I'cant use any library at all because i have to do it in a prod server, so no additional npm install can be done

Can't you use the `crypto` library built in to nodejs?

On the setup tab of a function node, add an import named crypto then in the on message tab...

```auto
const salt = crypto.randomBytes(256).toString('base64');
//Do what you need to with salt then return the result...
msg.payload = result
return msg;

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [31 May 2022 18:24 UTC](https://discourse.nodered.org/t/hash-salt-and-beyond/60591/7 "2022-05-31T18:24:13Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
