473,385 Members | 1,856 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,385 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 3097
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.