node_hash icon indicating copy to clipboard operation
node_hash copied to clipboard

Support multiple encodings

Open indexzero opened this issue 15 years ago • 6 comments

Currently node_hash only supports the 'hex' encoding. So it's impossible to use 'ascii' or 'utf8'.

Should be an easy fix: Add encoding to exported methods, default to 'hex' if nothing passed.

indexzero avatar Jan 23 '11 07:01 indexzero

I'm a little confused what the API would like look for this.

Could you show me some sample usage syntax?

Marak avatar Jan 28 '11 20:01 Marak

Rly? ok.

https://gist.github.com/800931

indexzero avatar Jan 28 '11 20:01 indexzero

I'm not sure how I could do the arguments parsing without making the salts "utf-8", "ascii" and "hex" reserved? Would that be your solution?

How can I tell the difference between:

  var md5 = hash.md5(user_password, 'utf8');

and

  var md5 = hash.md5(user_password, 'utf8');

, where one is telling me to use the default settings with a salt of "utf8" and the other is telling me to use utf-8 encoding with no salt?

Marak avatar Jan 28 '11 21:01 Marak

pass null as the second argument?

Marak avatar Jan 28 '11 21:01 Marak

I think,

  var md5 = hash.md5(user_password, 'utf-8');

and

  var md5 = hash.md5(user_password, null, 'utf8');

makes the most sense, where in the first example, 'utf-8' happens to be the salt. This makes the api require you to always send a salt, forcing you to send null if you ignored using a salt

Marak avatar Jan 28 '11 21:01 Marak

I would reserve the strings. using 'utf-8' as an encoding is not the same as using 'utf8' you could expose the strings as vars to help people:

var md5 = hash.md5(user_password, hash.utf8);

I would open up a larger discussion on the nodejs-dev list about pulling this into core if ambiguity is really a problem for you. I still think this belongs in core if Ry mentioned it as such.

indexzero avatar Jan 28 '11 21:01 indexzero