c#之如何计算哈希值字符串

代码如下:

    /// <summary>
    /// 计算哈希值字符串
    /// </summary>
    public static string ComputeHash(byte[] buffer)
    {
        if (buffer == null || buffer.Length < 1)
            return "";

        MD5 md5 = MD5.Create();
        byte[] hash = md5.ComputeHash(buffer);
        StringBuilder sb = new StringBuilder();

        foreach (var b in hash)
            sb.Append(b.ToString("x2"));

        return sb.ToString();
    }

转载请注明出处:http://www.cnblogs.com/jietian331/p/6928608.html

posted @ 2017-06-01 14:13  孤独の巡礼  阅读(5545)  评论(0编辑  收藏  举报