473,395 Members | 1,652 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,395 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 2052
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.