C# Equivalent of PHP's raw output MD5? -


i attempting implement 'simpler' version of (remote) wordpress login.

i have gotten far, bit stuck when comes wordpress algorithm encrypt password. code snippet 'class-phpass.php' (which wp uses hash password)...

$hash = md5($salt . $password, true); {     $hash = md5($hash . $password, true); } while (--$count); 

according php 5 manual -

string md5 ( string $str [, bool $raw_output = false ] ) 

"if optional raw_output set true, md5 digest instead returned in raw binary format length of 16."

to implement in c#, far, using code below, can found here:

public string md5sum(string strtoencrypt) {     system.text.utf8encoding ue = new system.text.utf8encoding();     byte[] bytes = ue.getbytes(strtoencrypt);      // encrypt bytes     md5cryptoserviceprovider md5 = new md5cryptoserviceprovider();     byte[] hashbytes = md5.computehash(bytes);      // convert encrypted bytes string (base 16)     string hashstring = "";      (int = 0; < hashbytes.length; i++)     {         hashstring += system.convert.tostring(hashbytes[i], 16).padleft(2, '0');     }      return hashstring.padleft(32, '0'); } 

as can see, c# version equivalent of php version, passing in false second parameter. have checked comparing output of both versions.

in addition, wordpress version passes true. struggling apply change c# version.

what c# equivalent of following php code?

$hash = md5($salt . $password, true); 

raw output means actual bytes, don't need convert them base16 string:

public static byte[] md5sum_raw(string strtoencrypt) {     system.text.utf8encoding ue = new system.text.utf8encoding();     byte[] bytes = ue.getbytes(strtoencrypt);      // encrypt bytes     md5cryptoserviceprovider md5 = new md5cryptoserviceprovider();     return md5.computehash(bytes); } 

php:

$s = md5('1234567890', true); ($i=0; $i < strlen($s); $i++)     echo ord($s[$i]) . ' '; 
232 7 241 252 248 45 19 47 155 176 24 202 103 56 161 159 

c#:

byte[] hash = md5sum_raw("1234567890"); (int = 0; < hash.length; i++)     system.console.out.write(hash[i] + " "); system.console.out.writeline();  232 7 241 252 248 45 19 47 155 176 24 202 103 56 161 159 

Comments