mirror of
https://github.com/Stone-Red-Code/HyperbolicDownloader.git
synced 2026-09-04 17:16:10 +02:00
29 lines
879 B
C#
29 lines
879 B
C#
using System.Security.Cryptography;
|
|
|
|
namespace HyperbolicDownloaderApi.FileProcessing;
|
|
|
|
internal static class FileValidator
|
|
{
|
|
public static async Task<string> CalculateHashAsync(string filePath)
|
|
{
|
|
using SHA512 sha = SHA512.Create();
|
|
using FileStream? stream = File.OpenRead(filePath);
|
|
byte[]? hash = await sha.ComputeHashAsync(stream);
|
|
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
|
}
|
|
|
|
public static string CalculateHash(string filePath)
|
|
{
|
|
return CalculateHashAsync(filePath).GetAwaiter().GetResult();
|
|
}
|
|
|
|
public static async Task<bool> ValidateHashAsync(string filePath, string hash)
|
|
{
|
|
return await CalculateHashAsync(filePath) == hash;
|
|
}
|
|
|
|
public static bool ValidateHash(string filePath, string hash)
|
|
{
|
|
return CalculateHash(filePath) == hash;
|
|
}
|
|
} |