Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js hash string?

Tags:

node.js

hash

I have a string that I want to hash. What's the easiest way to generate the hash in node.js?

The hash is for versioning, not security.

like image 212
Harry Avatar asked May 04 '11 04:05

Harry


People also ask

How do you hash in node JS?

For example, when we create a hash we first create an instance of Hash using crypto. createHash() and then we update the hash content using the update( ) function but till now we did not get the resulting hash value, So to get the hash value we use the digest function which is offered by the Hash class.

What is a hash string?

Hashing is the process of transforming any given key or a string of characters into another value. This is usually represented by a shorter, fixed-length value or key that represents and makes it easier to find or employ the original string. The most popular use for hashing is the implementation of hash tables.

How do I create a hash string?

In order to create a unique hash from a specific string, it can be implemented using their own string to hash converting function. It will return the hash equivalent of a string. Also, a library named Crypto can be used to generate various types of hashes like SHA1, MD5, SHA256 and many more.

What is MD5 in node JS?

MD5 stands for message digest 5 is a widely used hash function which produces 128-bit hashes. We are generating a simple hash using md5 hashing algorithm of node.js. Code. //md5-hash.js //Loading the crypto module in node.js var crypto = require('crypto'); //creating hash object var hash = crypto.


1 Answers

If you just want to md5 hash a simple string I found this works for me.

var crypto = require('crypto'); var name = 'braitsch'; var hash = crypto.createHash('md5').update(name).digest('hex'); console.log(hash); // 9b74c9897bac770ffc029102a200c5de 
like image 132
braitsch Avatar answered Sep 21 '22 20:09

braitsch