md5 helper

public static string ToMD5Hash(this string str)
{
    if (string.IsNullOrEmpty(str))
        return null;

    return Encoding.ASCII.GetBytes(str).ToMD5Hash();
}

public static string ToMD5Hash(this byte[] bytes)
{
    if (bytes == null || bytes.Length == 0)
        return null;

    using (var md5 = MD5.Create())
    {
        return string.Join("", md5.ComputeHash(bytes).Select(x => x.ToString("X2")));
    }
}

 

posted @ 2019-11-04 14:26  向萧  阅读(118)  评论(0编辑  收藏  举报