mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
27 lines
680 B
C#
27 lines
680 B
C#
using System.IO;
|
|
using System.Security.Cryptography;
|
|
|
|
namespace TEngine.Core
|
|
{
|
|
public static class MD5Helper
|
|
{
|
|
public static string FileMD5(string filePath)
|
|
{
|
|
using var file = new FileStream(filePath, FileMode.Open);
|
|
return FileMD5(file);
|
|
}
|
|
|
|
public static string FileMD5(FileStream fileStream)
|
|
{
|
|
var md5 = MD5.Create();
|
|
return md5.ComputeHash(fileStream).ToHex("x2");
|
|
}
|
|
|
|
public static string BytesMD5(byte[] bytes)
|
|
{
|
|
var md5 = MD5.Create();
|
|
bytes = md5.ComputeHash(bytes);
|
|
return bytes.ToHex("x2");
|
|
}
|
|
}
|
|
} |