MD5 encode diferent from Php

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a code in Php that does the md5(string1+string2+string3)

But i can't get the same in C#


Can anyone help me ?

Thanks
Ricardo Jesus
 
Try this method: Add the System.Security.Cryptography namespace in your
source code

public static string MD5(string password) {
byte[] textBytes = System.Text.Encoding.Default.GetBytes(password);
try {
System.Security.Cryptography.MD5CryptoServiceProvider
cryptHandler;
cryptHandler = new
System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] hash = cryptHandler.ComputeHash (textBytes);
string ret = "";
foreach (byte a in hash) {
if (a<16)
ret += "0" + a.ToString ("x");
else
ret += a.ToString ("x");
}
return ret ;
}
catch {
throw;
}
}

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
Thank you for your quick response.
It was very hellpfull.

My problem is solved.

Ricardo Jesus

John Timney (ASP.NET MVP) said:
Try this method: Add the System.Security.Cryptography namespace in your
source code

public static string MD5(string password) {
byte[] textBytes = System.Text.Encoding.Default.GetBytes(password);
try {
System.Security.Cryptography.MD5CryptoServiceProvider
cryptHandler;
cryptHandler = new
System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] hash = cryptHandler.ComputeHash (textBytes);
string ret = "";
foreach (byte a in hash) {
if (a<16)
ret += "0" + a.ToString ("x");
else
ret += a.ToString ("x");
}
return ret ;
}
catch {
throw;
}
}

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

Ricardo Jesus said:
I have a code in Php that does the md5(string1+string2+string3)

But i can't get the same in C#


Can anyone help me ?

Thanks
Ricardo Jesus
 
Back
Top