using System.Security.Cryptography; using System.Text; namespace Admin.NET.Plugin.AiDOP.DataPlatform.UnifiedIngress; internal static class MdpUploadSigningKeys { internal const string Reference = "managed:tenant-upload:v1"; // Provision once per environment; all API replicas use the same private signing root. internal static byte[] Derive(string accessKey) { var path = Environment.GetEnvironmentVariable("MDP_INGRESS_ISSUER_KEY_FILE"); if (string.IsNullOrWhiteSpace(path)) path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".aidop", "mdp-ingress-issuer-v1.key"); var root = File.ReadAllBytes(path); try { if (root.Length != 32) throw new InvalidOperationException("INGRESS_ISSUER_KEY_UNAVAILABLE"); return HMACSHA256.HashData(root, Encoding.UTF8.GetBytes(Reference + "/" + accessKey)); } finally { CryptographicOperations.ZeroMemory(root); } } }