C# and PHP compatible md5

Aug 15, 12:50

For one of my projects, I needed to be able to compute md5 hashes in both C# and PHP. I googled around, but didn’t find any wholly satisfactory answers. So, here’s a simple and fast function in C#:

using System.Security.Cryptography;
private string MD5(string StrToHash)
{
	byte[] hash = MD5CryptoServiceProvider.Create().ComputeHash(Encoding.ASCII.GetBytes(StrToHash));
	StringBuilder str = new StringBuilder();
	foreach(byte b in hash)
	{
		str.Append(b.ToString("x2"));
	}
	return str.ToString();
}

Note that you might want to use Encoding.UTF8.GetBytes(StrToHash) depending on the encoding/language of your input string.

VB

,

Your thoughts?

---

Newer »

Powered by textpattern