how to use crc32.checksum() and md5.digest() in nodejs

2,914 views
Skip to first unread message

jason.桂林

unread,
Dec 20, 2010, 9:54:56 PM12/20/10
to nod...@googlegroups.com
hashlib for node seems only generate string hash but not digest, fix me if I am wrong. How can I generate md5 digest or crc32 digest, which is faster?

--
Best regards,

Jason Green
桂林


Isaac Schlueter

unread,
Dec 20, 2010, 10:18:59 PM12/20/10
to nod...@googlegroups.com
Stream your data through the crypto module.


var Hash = require("crypto").Hash
, h = new Hash("md5")
, fs = require("fs")
, reader = fs.createReadStream("/etc/passwd")
reader.on("data", function (c) { h.update(c) })
reader.on("end", function () { console.log(h.digest("hex")) })

It'd be nice if the crypto Hash lib supported a similar surface to the
other stream APIs.

--i

> --
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en.
>

jason.桂林

unread,
Dec 20, 2010, 10:23:57 PM12/20/10
to nod...@googlegroups.com
This mthod is native c++ code or javascript code ?

Fedor Indutny

unread,
Dec 20, 2010, 10:26:20 PM12/20/10
to nod...@googlegroups.com
It's openssl bindings that are native for node.js

2010/12/21 jason.桂林 <gui...@gmail.com>

jason.桂林

unread,
Dec 20, 2010, 11:36:40 PM12/20/10
to nod...@googlegroups.com
hash.digest() returns a string object ,  how to getBytes of a string object

2010/12/21 Fedor Indutny <fe...@indutny.com>

Isaac Schlueter

unread,
Dec 20, 2010, 11:58:21 PM12/20/10
to nod...@googlegroups.com
Message has been deleted

Chris

unread,
Dec 21, 2010, 3:14:16 AM12/21/10
to nodejs
CRC32 is faster.

Go here (https://gist.github.com/749655) for an implementation

-Chris

jason.桂林

unread,
Dec 21, 2010, 8:33:17 AM12/21/10
to nod...@googlegroups.com
tested, this gist will only generate number less than 65535

--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.

Arnout Kazemier

unread,
Dec 21, 2010, 8:49:34 AM12/21/10
to nod...@googlegroups.com
I also created a crc32 hash function for node: https://github.com/3rd-Eden/node-memcached/blob/master/lib/hashring.js#L206-219
which i'm using for my memcached module. 

jason.桂林

unread,
Dec 21, 2010, 9:18:29 AM12/21/10
to nod...@googlegroups.com
looks not a fast implementation
Reply all
Reply to author
Forward
0 new messages