This commit is contained in:
Александр Бабаев 2023-02-11 08:15:03 +03:00
parent 6fd3f41e31
commit 553b5b0ec3
2 changed files with 22 additions and 3 deletions

View File

@ -1,4 +1,5 @@
using System.Security.Cryptography;
using System.Text;
using Microsoft.AspNetCore.Http;
@ -7,7 +8,7 @@ namespace anbs_cp.Classes;
/// <summary>
/// Класс для работы с хэшем файла
/// </summary>
public class FileHash
public sealed class FileHash
{
/// <summary>
/// Получение md5-хэша файла.
@ -35,14 +36,32 @@ public class FileHash
Hash = md5.ComputeHash(streamReader.BaseStream);
}
/// <summary>
/// Простой конструктор
/// </summary>
public FileHash ()
{
Hash = new byte[] { };
}
/// <summary>
/// Хэш файла
/// </summary>
public byte[] Hash { get; }
public byte[] Hash { get; private set; }
/// <summary>
/// Вывод в строку
/// </summary>
/// <returns>Строка хэша файла</returns>
public override string ToString () => BitConverter.ToString(Hash).Replace("-", "").ToLowerInvariant();
/// <summary>
/// Конвертирует строку в хэш
/// </summary>
/// <param name="value">Строка</param>
public void FromString (string value)
{
UTF8Encoding utf8 = new();
Hash = utf8.GetBytes(value);
}
}

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Version>2023.204.0</Version>
<Version>2023.211.0</Version>
<Authors>Alexander Babaev</Authors>
<Product>ANB Software Components Pack</Product>
<Description>Library of some useful functions in C# language.</Description>