Ah, yes, worked perfectly. Obvious, staring me right in the face.

Thanks very much, you rock.

R

On Monday, June 11, 2012 5:05:45 PM UTC-7, Ben Noordhuis wrote:
>
> On Tue, Jun 12, 2012 at 2:02 AM, Rich Jones <[email protected]> wrote: 
> > Can somebody help me sanity check something? 
> > 
> > I'm hashing some data using crypto.createHash, but the result isn't the 
> same 
> > as when I hash it using OpenSSL. What gives? 
> > 
> > With Node: 
> >   var file_data = fs.readFileSync(req.files.uploadfile.path, 'utf8'); 
> >   var sha1sum = crypto.createHash('sha1'); 
> >   sha1sum.update(file_data); 
> >   var d = sha1sum.digest('hex'); 
> >   console.log(d) // 3fb20f227f9d170f9b7631f79cb193631e223541 
> > 
> > With OpenSSL: 
> >    openssl sha1 file.png // 0dec33c8b6db53781aaa2b673723df744012c2c4 
> >    openssl sha1 /tmp/a8d54b0690c67c1bbaa374bece4f33b8 // 
> > 0dec33c8b6db53781aaa2b673723df744012c2c4 - hashes of local and uploaded 
> file 
> > match with oSSL 
> > 
> > Anybody have any ideas? I assume it's the way I'm reading the data. I've 
> > tried readFileSync with 'ascii' and get the same problem. 
>
> Read the file as a buffer or 'binary' and you should get the hash you 
> expect. 
>
> The PNG presumably contains binary data. If you read that in as ASCII 
> or UTF-8, it'll get mangled badly. 
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to