20230212-1
This commit is contained in:
		| @@ -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); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user