using System.Security.Cryptography;
using System.Text;

namespace StellaOps.Authority.Plugins.Abstractions;

/// <summary>
/// Deterministic hashing utilities for secrets managed by Authority plugins.
/// </summary>
public static class AuthoritySecretHasher
{
    /// <summary>
    /// Computes a stable SHA-256 hash for the provided secret.
    /// </summary>
    public static string ComputeHash(string secret)
    {
        if (string.IsNullOrEmpty(secret))
        {
            return string.Empty;
        }

        using var sha256 = SHA256.Create();
        var bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(secret));
        return Convert.ToBase64String(bytes);
    }
}
