forked from Eauldane/SnowcloakClient
Initial
This commit is contained in:
28
MareSynchronos/Utils/Crypto.cs
Normal file
28
MareSynchronos/Utils/Crypto.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace MareSynchronos.Utils;
|
||||
|
||||
public static class Crypto
|
||||
{
|
||||
#pragma warning disable SYSLIB0021 // Type or member is obsolete
|
||||
|
||||
private static readonly SHA256CryptoServiceProvider _sha256CryptoProvider = new();
|
||||
|
||||
public static string GetFileHash(this string filePath)
|
||||
{
|
||||
using SHA1CryptoServiceProvider cryptoProvider = new();
|
||||
return BitConverter.ToString(cryptoProvider.ComputeHash(File.ReadAllBytes(filePath))).Replace("-", "", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
public static string GetHash256(this string stringToHash)
|
||||
{
|
||||
return GetOrComputeHashSHA256(stringToHash);
|
||||
}
|
||||
|
||||
private static string GetOrComputeHashSHA256(string stringToCompute)
|
||||
{
|
||||
return BitConverter.ToString(_sha256CryptoProvider.ComputeHash(Encoding.UTF8.GetBytes(stringToCompute))).Replace("-", "", StringComparison.Ordinal);
|
||||
}
|
||||
#pragma warning restore SYSLIB0021 // Type or member is obsolete
|
||||
}
|
Reference in New Issue
Block a user