不知道从哪里拷来的函数,挺好用的。将c#的md5字符串保持跟php的md5函数一致。
public static string MD5ForPHP(string password) { byte[] textBytes = System.Text.Encoding.Default.GetBytes(password); try { System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler; cryptHandler = new System.Security.Cryptography.MD5CryptoServiceProvider(); 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; } }