Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

498
Views
How to create a hash token which output the same hash when the input is the same?

I am really getting a headache of this, so hopefully someone can help me.

I want to create an hashToken to save and secure some data. It is not sensitive data, so the security level doesn't need to be that high.

The scenario is like this. I receive data on the backend, which is something like a token already: 9ECB531EC6AE02CB0274336690E76A0A39511429859537BE242147B65B1824DD.

The next input is a different token, but the third input can be the same token as above. So when I receive a hashtoken that I already received earlier, this needs to be the same encryptedText as the one that alreadt existst.

I tried to save it via the crypto module of nodejs, like this:

const iv = randomBytes(16);
const password = 'VerySecurePasswordHere';
const key = (await promisify(scrypt)(password, 'salt', 32)) as Buffer;
const cipher = createCipheriv(
      'aes-256-ctr',
       key,
       iv
    );

const tokenToEncrypt =
      '9ECB531EC6AE02CB0274336690E76A0A39511429859537BE242147B65B1824DD';

const encryptedText = Buffer.concat([
      cipher.update(tokenToEncrypt),
      cipher.final(),
]);

output of encrypted text = 
0e2e913119d2699be2f3c6e5c7da8f03258207f19f3aea85014c9ce648730bea9faddb0c7dad1f49f73c5ff86051c6758d3573d4c28c972b859f8e4290c835c4

So this basically works, but two things are not working for my scenario:

  1. The encrypted text is too long. I want the output to have the same length/style as the input tokenToEncrypt.

  2. I am using cloud instances to run the code, so whenever the container goes idle and boots up again, the output of the same tokenToEncrypt will be totally different. This needs to be the same encrypted text as the one that is already saved in the database.

Do you have any tips for this to push me in the right direction? I tried also bCrypt, but then I also got a very long hashToken, and not in the same style as the input token.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Check out this SO answer to a similar question, I'm sure you'll find it very useful.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!