using System;
using System.Security.Cryptography;
namespace Dalamud.Utility;
///
/// Utility functions for hashing.
///
public static class Hash
{
///
/// Get the SHA-256 hash of a string.
///
/// The string to hash.
/// The computed hash.
internal static string GetStringSha256Hash(string text)
{
return string.IsNullOrEmpty(text) ? string.Empty : GetSha256Hash(System.Text.Encoding.UTF8.GetBytes(text));
}
///
/// Get the SHA-256 hash of a byte array.
///
/// The byte array to hash.
/// The computed hash.
internal static string GetSha256Hash(byte[] buffer)
{
using var sha = SHA256.Create();
var hash = sha.ComputeHash(buffer);
return ByteArrayToString(hash);
}
private static string ByteArrayToString(byte[] ba) => BitConverter.ToString(ba).Replace("-", string.Empty);
}