473,405 Members | 2,415 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,405 software developers and data experts.

php like md5 function

Hello,

Do you know how to mimic PHP md5 function? I'm using followin function,
but the results are different with PHP result when using Unicode (UTF-8)
characters. Someone please help me fix this...

Try compare PHP's result and following function result with this string
"Tiếng Việt"

PS: Hope you can read the string, this mail is in UTF-8.

------------------------------------------------------------
public static string Hash(string String)
{
byte[] buffer = System.Text.Encoding.Default.GetBytes(String);
try
{
System.Security.Cryptography.MD5CryptoServiceProvi der Check;
Check = new System.Security.Cryptography.MD5CryptoServiceProvi der();
byte[] Hash = Check.ComputeHash(buffer);
string HashString = "";
foreach (byte a in Hash)
{
if (a < 16)
{
HashString += "0" + a.ToString("X");
}
else
{
HashString += a.ToString("X");
}
}
return HashString.ToLower();
}
catch
{
throw;
}
}
------------------------------------------------------------
Nov 16 '05 #1
2 2053
FrzzMan <Fr*****@vnOCzone.com> wrote:
Do you know how to mimic PHP md5 function? I'm using followin function,
but the results are different with PHP result when using Unicode (UTF-8)
characters. Someone please help me fix this...


You need to find out what encoding PHP is using, and use the same one
to convert the string to bytes.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Jon Skeet [C# MVP] wrote:
FrzzMan <Fr*****@vnOCzone.com> wrote:
Do you know how to mimic PHP md5 function? I'm using followin function,
but the results are different with PHP result when using Unicode (UTF-8)
characters. Someone please help me fix this...

You need to find out what encoding PHP is using, and use the same one
to convert the string to bytes.


I tried almost every combination of .NET encoding, it didn't work...
I'll try to ask @ PHP newsgroup, btw, anyone here know something about this?

Requote the function:

Try compare PHP's result and following function result with this string
"Tiếng Việt"

PS: Hope you can read the string, this mail is in UTF-8.

------------------------------------------------------------
public static string Hash(string String)
{
byte[] buffer = System.Text.Encoding.Default.GetBytes(String);
try
{
System.Security.Cryptography.MD5CryptoServiceProvi der Check;
Check = new
System.Security.Cryptography.MD5CryptoServiceProvi der();
byte[] Hash = Check.ComputeHash(buffer);
string HashString = "";
foreach (byte a in Hash)
{
if (a < 16)
{
HashString += "0" + a.ToString("X");
}
else
{
HashString += a.ToString("X");
}
}
return HashString.ToLower();
}
catch
{
throw;
}
}
------------------------------------------------------------
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
by: phil_gg04 | last post by:
Dear Javascript Experts, Opera seems to have different ideas about the visibility of Javascript functions than other browsers. For example, if I have this code: if (1==2) { function...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
2
by: sushil | last post by:
+1 #include<stdio.h> +2 #include <stdlib.h> +3 typedef struct +4 { +5 unsigned int PID; +6 unsigned int CID; +7 } T_ID; +8 +9 typedef unsigned int (*T_HANDLER)(void); +10
8
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.