Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Same hash for integer #3

Closed
damodaran opened this Issue Nov 25, 2012 · 3 comments

Comments

Projects
None yet
3 participants

Hi

I try to generate random hash as

var md5 = require('MD5');
var dt = (new Date).getTime();
var hash = md5( Math.floor((Math.random() * 100000) + 1) +  dt);
//hash = d41d8cd98f00b204e9800998ecf8427e[always]

But it shows the same hash even the dt and random numbers are different.

i solve this by converting the random integer to string by appending toString():

var dt = (new Date).getTime();
var hash = md5( (Math.floor((Math.random() * 100000) + 1) +  dt).toString());
Owner

pvorb commented Nov 25, 2012

In its current state the algorithm expects strings or byte arrays as messages (see line 11). I should have noted that in the Readme.

Nevertheless, I should simply fix that behavior by adding a toString() for other values than string and byte array.

@pvorb pvorb added a commit that referenced this issue Nov 25, 2012

@pvorb pvorb fix issue #3 same hash for random integers
custom behavior for everything other than string or byte array
404110a

@pvorb pvorb closed this Nov 25, 2012

tobscher commented May 26, 2016 edited

It looks like in its current state md5(12345) and md5('12345') will still return different results. I am wondering if this is due to the fact that Strings get converted into byte arrays and integers are not. What is the expected outcome?

Owner

pvorb commented May 27, 2016

Calling md5 with something different than strings or buffers is undefined behaviour.

Tobias Haar notifications@github.com schrieb:

It looks like in it's current state md5(12345) and md5('12345') will still return different results. I am wondering if this is due to the fact that Strings get converted into byte arrays and integers are not. What is the expected outcome?


You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#3 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment