1

I want to md5-hash a string using javascript. I have to compare the result to an ldap-md5-hashed string (password). But the results are different: For the string 'test' javascript md5 is

098f6bcd4621d373cade4e832627b4f6

LDAP on the other hand saved

CY9rzUYh03PK3k6DJie09g==

as the password string.

The LDAP-md5 can as well be generated using PHP by executing this

base64_encode(md5("test", true));

I'm using the following javascript hash function from this post: How to generate MD5 file hash on javascript?

var MD5 = function(d){result = M(V(Y(X(d),8*d.length)));return result.toLowerCase()};function M(d){for(var ,m="0123456789ABCDEF",f="",r=0;r>>4&15)+m.charAt(15&);return f}function X(d){for(var =Array(d.length>>2),m=0;m<.length;m++)[m]=0;for(m=0;m<8*d.length;m+=8)[m>>5]|=(255&d.charCodeAt(m/8))<="",m=0;m<32*d.length;m+=8)+=String.fromCharCode(d[m>>5]>>>m%32&255);return }function Y(d,){d[>>5]|=128<<%32,d[14+(+64>>>9<<4)]=;for(var m=1732584193,f=-271733879,r=-1732584194,i=271733878,n=0;n>16)+(_>>16)+(m>>16)<<16|65535&m}function bit_rol(d,){return d<<|d>>>32-_}

How do I calculate the exact same md5 hash in javascript, so that it matches the one from LDAP (as well as PHP)?

Galveston01
  • 356
  • 2
  • 13

1 Answers1

1

I ended up copying this javascript md5 library: https://github.com/emn178/js-md5/blob/master/src/md5.js

Here I can generate an LDAP-equivalent md5 hash as simple as:

md5.base64("test");

Galveston01
  • 356
  • 2
  • 13