mlaumcherb/Mlaumcherb.Client.Avalonia/холопы/HashHelper.cs

32 lines
731 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
return sha1 is not null && HashFileSHA1(f) == sha1;
return true;
}
}