n°达达的主页1234n.com个人博客 / 旧文存档
← 返回文章
2011-07-19 / 达达

C#中与PHP格式对应的md5函数

分享PHPC#

如题


public static string MD5(string password)
{
    byte[] textBytes = System.Text.Encoding.Default.GetBytes(password);

    System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler;
    cryptHandler = new System.Security.Cryptography.MD5CryptoServiceProvider();

    byte[] hash = cryptHandler.ComputeHash(textBytes);

    StringBuilder ret = new StringBuilder(32);

    foreach (byte a in hash)
    {
        if (a < 16)
            ret.Append("0").Append(a.ToString("x"));
        else
            ret.Append(a.ToString("x"));
    }

    return ret.ToString();
}

原标签已从 2023-12-16 存档快照 恢复。本文按原站快照恢复排版,并接回已核实的本地图片。查看恢复说明