mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-07-12 10:09:32 +00:00
25 lines
678 B
C#
25 lines
678 B
C#
|
|
using System.Security.Cryptography;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
namespace Utils
|
|||
|
|
{
|
|||
|
|
public static class FileHash
|
|||
|
|
{
|
|||
|
|
public static string HashContents(string fileContents)
|
|||
|
|
{
|
|||
|
|
var fileBytes = Encoding.ASCII.GetBytes(fileContents
|
|||
|
|
.Replace(Environment.NewLine, "")
|
|||
|
|
.Replace(" ", "")); // Ignore whitespace deviations in openapi.yaml
|
|||
|
|
|
|||
|
|
var hash = SHA256.HashData(fileBytes);
|
|||
|
|
return BitConverter.ToString(hash);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static string Hash(string filePath)
|
|||
|
|
{
|
|||
|
|
var file = File.ReadAllText(filePath);
|
|||
|
|
return HashContents(file);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|