Question

I'm using the CryptoJS library for Javascript MD5 and SHA256 hashing: https://code.google.com/p/crypto-js/

The SHA256 stuff is working fine, but I can't convert the MD5 hash result from a word array back into a string. Below is the code I'm using to just degug the problem - I've subbed out the actual hash results, and added the console.log() output as comments

email_hash = $rootScope.session.email.toLowerCase();

console.log('email', email_hash);
// email email@example.com

sha_hash = CryptoJS.SHA256(email_hash).toString(CryptoJS.enc.Hex);

console.log('sha', sha_hash);
// sha SHA256-VALUE-OUTPUTS-FINE

email_hash = CryptoJS.MD5( email_hash );

console.log( JSON.stringify( email_hash ) );
//{"words":[0000000000,-0000000000,-00000000000,0000000000],"sigBytes":16}

a = email_hash.toString( CryptoJS.enc.Latin1 );
b = email_hash.toString( CryptoJS.enc.Hex );

console.log( a, b );
// [object Object] [object Object] 

What am I doing wrong with the MD5 result?

Was it helpful?

Solution

Oh ok - the answer is not in the code I posted.

I was using version 3.0.2 of the SHA256 code, and version 3.1.2 for MD5.

Updating SHA256 to 3.1.2, so they are both on the same version, has fixed it. I'm including the SHA256 before the MD5, so it must have been overwriting something in the MD5 file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top