Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  160] [ 3]  / answers: 1 / hits: 7662  / 11 Years ago, wed, february 19, 2014, 12:00:00

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 protected]

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?


More From » hash

 Answers
3

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.




[#47590] Tuesday, February 18, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
larrycodys

Total Points: 394
Total Questions: 93
Total Answers: 78

Location: Romania
Member since Mon, Jun 6, 2022
2 Years ago
;