Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to import passwords from an LDAP to a MySQL database. When I look at the userPassword attribute for the known password test I get this:

userPassword:: e01ENX1DWTlyelVZaDAzUEszazZESmllMDlnPT0=

The password at this stage is base64 encoded, after decoding I get this:


-It doesn't look like the CY9.... string is an MD5 hash because it isn't 32-character long (actually 128-bit).
-It doesn't seem to be base64 encoded either as I don't get test after decoding.
-Also when I generate my own MD5 hash out of test I get 098f6bcd4621d373cade4e832627b4f6.

I found this perl script (second one on the page) which does generate {MD5}CY9rzUYh03PK3k6DJie09g== from test but when I look at the script I don't see what I'm missing as it does look like the md5 hash gets base64 encoded before being concatenated with {MD5}:

$ctx = Digest::MD5->new;
$hashedPasswd = '{MD5}' . encode_base64($ctx->digest,'');

Can someone explain the step to get from test to CY9rzUYh03PK3k6DJie09g==?

share|improve this question
up vote 2 down vote accepted

Have you checked the second parameter of the PHP md5() function?

cat md5.php 
<?php echo base64_encode(md5('test',true));

php md5.php 

You should use the raw binary format (and that's why it was encoded with base64).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.