using System.Security.Cryptography; using System.Text; namespace Admin.NET.Plugin.AiDOP.DataPlatform.Core; public static class PurchaseDispatchProof { public const string DigestHeader = "X-Mdp-Dispatch-Digest"; public const string ProofHeader = "X-Mdp-Dispatch-Proof"; public const string CredentialSetting = "MDP_PURCHASE_DISPATCH_KEY"; public static byte[] Sign(byte[] key, string method, string path, string digest) => HMACSHA256.HashData(key, Encoding.UTF8.GetBytes($"purchase-dispatch-v1\n{method}\n{path}\n{digest}")); public static byte[]? ReadKey(string? value) { var key = new byte[32]; return value?.Length == 44 && Convert.TryFromBase64String(value, key, out var count) && count == key.Length ? key : null; } }