Initial commit: scadaproj umbrella — sister-project index, auth component normalization (design + GAPS), and the built ZB.MOM.WW.Auth shared library (0.1.0, flattened in).

This commit is contained in:
dohertj2
2026-06-01 03:59:23 -04:00
commit 37e23cf9f2
73 changed files with 6836 additions and 0 deletions
@@ -0,0 +1,30 @@
using System.Security.Cryptography;
using System.Text;
namespace ZB.MOM.WW.Auth.ApiKeys;
internal static class ApiKeySecretHasher
{
/// <summary>
/// Computes HMAC-SHA256(key: UTF-8(pepper), data: UTF-8(secret)).
/// </summary>
public static byte[] Hash(string secret, string pepper)
{
byte[] pepperBytes = Encoding.UTF8.GetBytes(pepper);
byte[] secretBytes = Encoding.UTF8.GetBytes(secret);
using HMACSHA256 hmac = new(pepperBytes);
return hmac.ComputeHash(secretBytes);
}
/// <summary>
/// Returns true iff HMAC-SHA256(key: UTF-8(pepper), data: UTF-8(secret)) equals
/// <paramref name="expectedHash"/>, using a constant-time comparison.
/// Returns false (without throwing) if the lengths differ.
/// </summary>
public static bool Verify(string secret, string pepper, byte[] expectedHash)
{
byte[] actualHash = Hash(secret, pepper);
return CryptographicOperations.FixedTimeEquals(actualHash, expectedHash);
}
}