mirror of
https://github.com/Stone-Red-Code/HyperbolicDownloader.git
synced 2026-09-04 17:16:10 +02:00
19 lines
602 B
C#
19 lines
602 B
C#
using System.Security.Cryptography;
|
|
|
|
namespace HyperbolicDowloader.FileProcessing;
|
|
|
|
internal 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 async Task<bool> ValidateHashAsync(string filePath, string hash)
|
|
{
|
|
return await CalculateHashAsync(filePath) == hash;
|
|
}
|
|
} |