32 lines
731 B
C#
32 lines
731 B
C#
using System.Security.Cryptography;
|
||
using DTLib.Extensions;
|
||
|
||
namespace Mlaumcherb.Client.Avalonia.холопы;
|
||
|
||
public static class HashHelper
|
||
{
|
||
private static SHA1 _hasher;
|
||
|
||
static HashHelper()
|
||
{
|
||
_hasher = SHA1.Create();
|
||
}
|
||
|
||
public static string HashFileSHA1(IOPath f)
|
||
{
|
||
using var fs = File.OpenRead(f);
|
||
byte[] hash = _hasher.ComputeHash(fs);
|
||
return hash.HashToString();
|
||
}
|
||
|
||
public static bool CheckFileSHA1(IOPath f, string? sha1, bool checkHash)
|
||
{
|
||
if (!File.Exists(f))
|
||
return false;
|
||
|
||
if(checkHash && sha1 is not null)
|
||
return HashFileSHA1(f) == sha1;
|
||
|
||
return true;
|
||
}
|
||
} |