Dalamud/Dalamud/Utility/Hash.cs
goat 448b0d16ea
Add "loading dialog" for service init, unify blocking logic (#1779)
* wip

* hacky fix for overlapping event text in profiler

* move IsResumeGameAfterPluginLoad logic to PluginManager

* fix some warnings

* handle exceptions properly

* remove ability to cancel, rename button to "hide" instead

* undo Dalamud.Service refactor for now

* warnings

* add explainer, show which plugins are still loading

* add some text if loading takes more than 3 minutes

* undo wrong CS merge
2024-04-21 17:28:37 +02:00

33 lines
1 KiB
C#

using System.Security.Cryptography;
namespace Dalamud.Utility;
/// <summary>
/// Utility functions for hashing.
/// </summary>
public static class Hash
{
/// <summary>
/// Get the SHA-256 hash of a string.
/// </summary>
/// <param name="text">The string to hash.</param>
/// <returns>The computed hash.</returns>
internal static string GetStringSha256Hash(string text)
{
return string.IsNullOrEmpty(text) ? string.Empty : GetSha256Hash(System.Text.Encoding.UTF8.GetBytes(text));
}
/// <summary>
/// Get the SHA-256 hash of a byte array.
/// </summary>
/// <param name="buffer">The byte array to hash.</param>
/// <returns>The computed hash.</returns>
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);
}