36 lines
906 B
C#
36 lines
906 B
C#
using System.IO;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace KamihamaWeb.Util
|
|
{
|
|
public class CryptUtil
|
|
{
|
|
public static string CalculateMd5File(string filename)
|
|
{
|
|
using var md5 = MD5.Create();
|
|
using var stream = File.OpenRead(filename);
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
foreach (byte b in md5.ComputeHash(stream))
|
|
{
|
|
sb.Append(b.ToString("x2"));
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
public static string CalculateSha256(string text)
|
|
{
|
|
using var sha = SHA256.Create();
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
foreach (byte b in sha.ComputeHash(Encoding.UTF8.GetBytes(text)))
|
|
{
|
|
sb.Append(b.ToString("x2"));
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
} |