How to generate random SHA1 hash to use as ID in node.js?

后端 未结 4 1612
有刺的猬
有刺的猬 2020-12-04 04:45

I am using this line to generate a sha1 id for node.js:

crypto.createHash(\'sha1\').digest(\'hex\');

The problem is that it\'s returning th

4条回答
  •  春和景丽
    2020-12-04 05:21

    Have a look here: How do I use node.js Crypto to create a HMAC-SHA1 hash? I'd create a hash of the current timestamp + a random number to ensure hash uniqueness:

    var current_date = (new Date()).valueOf().toString();
    var random = Math.random().toString();
    crypto.createHash('sha1').update(current_date + random).digest('hex');
    

提交回复
热议问题