Nodejs md5 with base64 digest algorithm incorrect result

here is my code

var sig = crypto.createHash('md5') .update('The quick brown fox jumps over the lazy dog') .digest('base64'); console.log(sig) 

leads to nhB9nTcrtoJr2B01QqQZ1g== (on Mac OS X).

I am trying to create the same signature from an ios application. The results are the same in object c, as in converter online sites: line

The quick brown fox jumps over the lazy dog

converted to md5 , I get 9e107d9d372bb6826bd81d3542a419d6 ,

and base64 is OWUxMDdkOWQzNzJiYjY4MjZiZDgxZDM1NDJhNDE5ZDY= .

Why are these lines different? Isn't that what nodejs cryptography module does? What is equivalent to nodejs algorithm for getting base64 digested md5 hash?

+7
source share
1 answer

The string OWUxMDdkOWQzNzJiYjY4MjZiZDgxZDM1NDJhNDE5ZDY= is the base64 encoded version of the string 9e107d9d372bb6826bd81d3542a419d6 , which itself is the md5 hash of the plain text string The quick brown fox jumps over the lazy dog .

If you want to do this in node, you first need to get the md5 hash in hex:

 var crypto = require('crypto'); var s = 'The quick brown fox jumps over the lazy dog'; var md5 = crypto.createHash('md5').update(s).digest('hex'); 

Now you have the md5 hash as hex ( 9e107d9d372bb6826bd81d3542a419d6 ). Now all you have to do is convert it to base64:

 new Buffer(md5).toString('base64'); 
+13
source

All Articles