md5($str)

 



public static string MD5(byte[] val)
{
byte[] textBytes = val;
try
{
System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler;
cryptHandler = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] hash = cryptHandler.ComputeHash(textBytes);
string ret = "";
foreach (byte a in hash)
{
ret += a.ToString("x2");
}
return ret;
}
catch
{
throw;
}
}


 

注意:

    1. C#端传入的参数为byte[],php端使用$str作为参数。

    2. C#端不要使用System.Text.Encoding.Default.GetBytes(bytes)去转字符串,C#端各种byte[]到string之间的转换都会产生和php之间的冲突。