-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelpers.cs
26 lines (21 loc) · 916 Bytes
/
Helpers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System;
using System.Collections;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Security.Cryptography;
using System.Text;
using System.Xml;
static class Helpers
{
static readonly SHA1 sha1 = SHA1.Create();
internal static XmlElement Deserialize(string input)
{
using var reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(input), XmlDictionaryReaderQuotas.Max);
XmlDocument xml = new();
xml.Load(reader);
return xml["root"];
}
internal static string Hash(Stream inputStream) { return ToString(sha1.ComputeHash(inputStream)); }
internal static string Hash(string path) { return File.Exists(path) ? ToString(sha1.ComputeHash(File.ReadAllBytes(path))) : string.Empty; }
static string ToString(byte[] value) { return BitConverter.ToString(value).Replace("-", string.Empty); }
}