PurchaseDispatchProof.cs 778 B

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