php like md5 function

  • Thread starter Thread starter FrzzMan
  • Start date Start date
F

FrzzMan

Hello,

Do you know how to mimic PHP md5 function? I'm using followin function,
but the results are different with PHP result when using Unicode (UTF-8)
characters. Someone please help me fix this...

Try compare PHP's result and following function result with this string
"Tiếng Việt"

PS: Hope you can read the string, this mail is in UTF-8.

------------------------------------------------------------
public static string Hash(string String)
{
byte[] buffer = System.Text.Encoding.Default.GetBytes(String);
try
{
System.Security.Cryptography.MD5CryptoServiceProvider Check;
Check = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] Hash = Check.ComputeHash(buffer);
string HashString = "";
foreach (byte a in Hash)
{
if (a < 16)
{
HashString += "0" + a.ToString("X");
}
else
{
HashString += a.ToString("X");
}
}
return HashString.ToLower();
}
catch
{
throw;
}
}
------------------------------------------------------------
 
FrzzMan said:
Do you know how to mimic PHP md5 function? I'm using followin function,
but the results are different with PHP result when using Unicode (UTF-8)
characters. Someone please help me fix this...

You need to find out what encoding PHP is using, and use the same one
to convert the string to bytes.
 
Jon said:
You need to find out what encoding PHP is using, and use the same one
to convert the string to bytes.

I tried almost every combination of .NET encoding, it didn't work...
I'll try to ask @ PHP newsgroup, btw, anyone here know something about this?

Requote the function:

Try compare PHP's result and following function result with this string
"Tiếng Việt"

PS: Hope you can read the string, this mail is in UTF-8.

------------------------------------------------------------
public static string Hash(string String)
{
byte[] buffer = System.Text.Encoding.Default.GetBytes(String);
try
{
System.Security.Cryptography.MD5CryptoServiceProvider Check;
Check = new
System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] Hash = Check.ComputeHash(buffer);
string HashString = "";
foreach (byte a in Hash)
{
if (a < 16)
{
HashString += "0" + a.ToString("X");
}
else
{
HashString += a.ToString("X");
}
}
return HashString.ToLower();
}
catch
{
throw;
}
}
------------------------------------------------------------
 
Back
Top