Subscribed unsubscribe Subscribe Subscribe

@peccul is peccu

(love peccu '(emacs lisp cat outdoor bicycle mac linux coffee))

Node.jsでmd5、sha1

md5sha1のメモ

var crypto = require('crypto');  
var hasher = function(type){
  return function(src){
    var hash = crypto.createHash(type);
    hash.update(src, 'binary');
    return hash.digest('hex');
  };
};

var md5 = hasher('md5');
var sha1 = hasher('sha1');

md5('hogehoge'); // => 329435e5e66be809a656af105f42401e
sha1('hogehoge'); // => 3b2c6c10d0e78072d14e02cc4c587814d0f10f3a
% php -a
Interactive shell

php > echo md5('hogehoge');
329435e5e66be809a656af105f42401e
php > echo sha1('hogehoge');
3b2c6c10d0e78072d14e02cc4c587814d0f10f3a