52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace LY.App.Common.Cypher
|
|
{
|
|
public class MD5CypherUtil
|
|
{
|
|
/// <summary>
|
|
/// MD5加密
|
|
/// </summary>
|
|
/// <param name="str">内容</param>
|
|
/// <returns></returns>
|
|
public static string Hash(string str)
|
|
{
|
|
return Hash(Encoding.UTF8.GetBytes(str));
|
|
}
|
|
|
|
/// <summary>
|
|
/// MD5加密
|
|
/// </summary>
|
|
/// <param name="buffer"></param>
|
|
/// <returns></returns>
|
|
public static string Hash(byte[] buffer)
|
|
{
|
|
return BitConverter.ToString(BinaryHash(buffer)).Replace("-", "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// MD5加密
|
|
/// </summary>
|
|
/// <param name="buffer"></param>
|
|
/// <returns></returns>
|
|
public static byte[] BinaryHash(string str)
|
|
{
|
|
return BinaryHash(Encoding.UTF8.GetBytes(str));
|
|
}
|
|
|
|
/// <summary>
|
|
/// MD5加密
|
|
/// </summary>
|
|
/// <param name="buffer"></param>
|
|
/// <returns></returns>
|
|
public static byte[] BinaryHash(byte[] buffer)
|
|
{
|
|
using (var md5 = MD5.Create())
|
|
{
|
|
return md5.ComputeHash(buffer);
|
|
}
|
|
}
|
|
}
|
|
}
|