471,339 Members | 1,156 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,339 software developers and data experts.

MD5 encode diferent from Php

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
Jul 21 '05 #1
2 3024
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.MD5CryptoServiceProvi der
cryptHandler;
cryptHandler = new
System.Security.Cryptography.MD5CryptoServiceProvi der();
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" <Ri**********@discussions.microsoft.com> wrote in message
news:1D**********************************@microsof t.com...
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

Jul 21 '05 #2
Thank you for your quick response.
It was very hellpfull.

My problem is solved.

Ricardo Jesus

"John Timney (ASP.NET MVP)" wrote:
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.MD5CryptoServiceProvi der
cryptHandler;
cryptHandler = new
System.Security.Cryptography.MD5CryptoServiceProvi der();
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" <Ri**********@discussions.microsoft.com> wrote in message
news:1D**********************************@microsof t.com...
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


Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by francescomoi | last post: by
1 post views Thread by rrosa | last post: by
3 posts views Thread by Peter | last post: by
4 posts views Thread by Darrel | last post: by
6 posts views Thread by 7stud | last post: by
1 post views Thread by anonymous | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.