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
RicardoJesus [ Do, 20 Januar 2005 13:39 ] [ ID #597495 ]

Re: MD5 encode diferent from Php

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" <RicardoJesus [at] discussions.microsoft.com> wrote in message
news:1DC08915-2D5D-4885-B837-C44C48C85147 [at] microsoft.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
timneyj [ Do, 20 Januar 2005 14:34 ] [ ID #597500 ]

Re: MD5 encode diferent from Php

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.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" <RicardoJesus [at] discussions.microsoft.com> wrote in message
> news:1DC08915-2D5D-4885-B837-C44C48C85147 [at] microsoft.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
>
>
>
RicardoJesus [ Do, 20 Januar 2005 15:17 ] [ ID #597505 ]

RE: MD5 encode diferent from Php

What is the similar in VB for this section?

foreach (byte a in hash) {
if (a<16)
ret += "0" + a.ToString ("x");
else
ret += a.ToString ("x");
}


From http://www.developmentnow.com/g/34_2005_1_0_0_41487/MD5-enco de-diferent-from-Php.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Foong [ Mi, 30 Januar 2008 03:01 ] [ ID #1919794 ]
Microsoft » microsoft.public.dotnet.general » MD5 encode diferent from Php

Vorheriges Thema: Popup appears " Installing COM Components" on Opening of MS Excel
Nächstes Thema: Screen Scraping Questions