Skip to content

Instantly share code, notes, and snippets.

@shinout
Created December 20, 2011 03:40
Show Gist options
  • Save shinout/1500125 to your computer and use it in GitHub Desktop.
Save shinout/1500125 to your computer and use it in GitHub Desktop.
md5
var crypto = require('crypto');
var md5sum = crypto.createHash('md5');
md5sum.update('shinout', 'utf8');
console.log(md5sum.digest('hex'));
@shinout
Copy link
Author

shinout commented Jan 18, 2012

The 2nd argument of md5sum.update ("utf8") is necessary for multi-byte strings.
Otherwise, we can get wrong result and collision would easily happen.

For example,
"場所": "place" in English
and
"水着" : "swimsuits" in English

return the same hash result if we omit the second argument.

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