input是你要加密的内容

public static string GetMd5Hash(string input)
{
    MD5 md5Hash = MD5.Create();
    // Convert the input string to a byte array and compute the hash.
    byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
    StringBuilder sBuilder = new StringBuilder();
    for (int i = 0; i < data.Length; i++)
    {
        sBuilder.Append(data[i].ToString("x2"));
    }
    return sBuilder.ToString();
}

然后返回的就是加密后的一串数字

ToString("x2"):转化为16进制的两位数字

x:16进制,

2:两位数字

 posted on 2016-11-03 11:59  布鲁布鲁sky  阅读(265)  评论(0编辑  收藏  举报