using System;
using System.Security.Cryptography;
using System.Text;
namespace MAX.Core.Cryptography;
public class MD5Helper
{
///
/// MD5加密
///
///
///
public static string Md5_32(string instring)
{
return _Md532(instring);
}
public static string Md5_Lower32(string instring)
{
return _Md532(instring, true);
}
public static string _Md532(string instring, bool IsLower = false)
{
byte[] result = Encoding.UTF8.GetBytes(string.IsNullOrEmpty(instring) ? "" : instring.Trim());
MD5 md5 = MD5.Create();
byte[] output = md5.ComputeHash(result);
string value = BitConverter.ToString(output).Replace("-", "");
if (IsLower)
{
return value.ToLower();
}
return value;
}
///
/// MD5加密
///
///
public static long GetLong(byte[] result)
{
return
Convert.ToInt64(
BitConverter.ToString(MD5.Create().ComputeHash(result), 4,
8).Replace("-", ""), 16);
}
///
/// MD5 16位加密转long
///
///
///
public static long GetLong(string url)
{
if (string.IsNullOrEmpty(url))
{
return 0;
}
return Convert.ToInt64(BitConverter.ToString(MD5.Create().ComputeHash(Encoding.Default.GetBytes(url)), 4, 8).Replace("-", ""), 16);
}
}