473,238 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,238 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 3092
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: francescomoi | last post by:
Hi. I'm trying to store a text within a MySQL field (v 3.23.58) by using MySQLdb (v 1.2.1c3). The text is: "telephone..." (note the last character) And I get this error message:...
1
by: rrosa | last post by:
Hi there, I am trying to create a window that appears one label1="First Message" and after of 3,4 seconds I would like to append another label in the same window label2="Second Message" bellow of...
4
by: Newbie | last post by:
How would I modify this form to encode *all* the characters in the 'source' textarea to the '%xx' format & place result code into the 'output' textarea? (cross browser compatable) Any help is...
3
by: Peter | last post by:
Hi, I try to make up a javascript string which contains numeric numbers in any positions. For example, I want to make a string: secretcode, where secretcode.charAt(0)==(-21),...
1
by: Bernardo | last post by:
Hi, Anyone knows how can I sellect a diferent cell or Row at runtime? Thanks a lot
4
by: Darrel | last post by:
How does HTML.encode work? I'm trying to save text in a hidden form field into a SQL DB. The tedt is HTML (from a WYSIWYG editor...X-standard). One problem I have is that stray apostrophe's in...
3
by: Ivan | last post by:
Thanks to answer topic previous!!!! I use this script to update one table MERGE INTO EIS.CLI_HISTORY TXN USING EIS.CLI_MAPING CLI ON TXN.CLIENTID = CLI.CLIENTID WHEN MATCHED AND...
6
by: 7stud | last post by:
s1 = "hello" s2 = s1.encode("utf-8") s1 = "an accented 'e': \xc3\xa9" s2 = s1.encode("utf-8") The last line produces the error: --- Traceback (most recent call last):
4
by: J Peyret | last post by:
Well, as usual I am confused by unicode encoding errors. I have a string with problematic characters in it which I'd like to put into a postgresql table. That results in a postgresql error so I...
1
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.