skip to Main Content
const { hashGen } = require('crypto');

var hash = hashGen('sha256').update(hash).digest('hex');

I am being given the error:
TypeError: hashGen is not a function

I tried to create a password with a salt in front of it, and then hash it with SHA-256, but I am just getting the error upon running.

2

Answers


  1. I think you are writing the function wrong

    you can create with:

    const hash = crypto.createHash('sha256', secret)
    

    https://www.geeksforgeeks.org/node-js-crypto-createhash-method/

    and if you want to make a password hash, try Bcrypt, sha256 is safe but is a fast hash, is not impossivble to discover, exist databases to this (with inumerous hashs and your content)

    Login or Signup to reply.
  2. There’s exactly your case. API

    const { createHmac } = require('node:crypto');
    
    const secret = 'abcdefg';
    const hash = createHmac('sha256', secret)
                   .update('I love cupcakes')
                   .digest('hex');
    console.log(hash);
    // Prints:
    //   c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search