How can I do a local and remote HMAC comparison in an Azure Workflow

I have a C# script embedded in an ‘Execute CSharp Script Code’ object on an Azure workflow.
This takes an external HMAC key passed in the header and some JSON text in the body as input and needs to calculate a new HMAC locally and compare the two for authenticity.
My HMAC strings aren’t matching because the output body type is as shown below when the original is formatted.

My testing script:

// Add the required libraries
#r "Newtonsoft.Json"
#r "Microsoft.Azure.Workflows.Scripting"
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Microsoft.Extensions.Logging;
using Microsoft.Azure.Workflows.Scripting;
using Newtonsoft.Json.Linq;
using System.Security.Cryptography;
using System.Text;

/// <summary>
/// Executes the inline csharp code.
/// </summary>
/// <param name="context">The workflow context.</param>
/// <remarks> This is the entry-point to your code. The function signature should remain unchanged.</remarks>
public static async Task<Results> Run(WorkflowContext context, ILogger log)
{
  //String Variables (for clarity)
  string compare = string.Empty;
  string _origonalMessage = string.Empty;
  string _origonalHmac = string.Empty;
  string _calculatedHmac = string.Empty;

  ////Define the trigger output.
  var triggerOutputs = (await context.GetTriggerResults().ConfigureAwait(false)).Outputs;

  ////Set the local HMAC key from the Azure Key Vault.
  string secretKey = "HMAC-GG-TEST"; // <-- Temporary for testing.
  //I need to make a key vault get the secret from this.
  //Maybe something like: var secretKeysTEST = await client.GetSecretAsync(HMAC);
  
  ////Set the whole JSON body text  from the trigger.
  var origonalMessage = triggerOutputs["body"].ToString();
  _origonalMessage = origonalMessage;

  ////Set the remote HMAC encrypted text from the Azure header. (needs to be the input header)
  var receievedHmac = triggerOutputs?["headers"]?["HMACEncripted"]?.ToString();
  _origonalHmac = receievedHmac;

  ////Encrypt the body text with the local HMAC key and compare with the remote Encrypted text.
  //convert key and message to byte arrays
  byte[] keyBytes = Encoding.UTF8.GetBytes(secretKey);
  byte[] messageBytes = Encoding.UTF8.GetBytes(origonalMessage);

  //Create an HMAC SHA256 instance with the local key
  using (HMACSHA256 hmac = new HMACSHA256(keyBytes))
    {
        //Compute the HMAC and convert it to a string
        byte[] hashBytes = hmac.ComputeHash(messageBytes);
        var localHmac = BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
    _calculatedHmac = localHmac;
  }

  //Compare the computed HMAC with the received HMAC
  string testString = "GAURAV";
  if (_calculatedHmac.Equals(receievedHmac, StringComparison.OrdinalIgnoreCase))
  {
    compare = "Match";
  }
  else
  {
    compare = "noMatch:  Calc=" + _calculatedHmac + "  Orig=" + _origonalHmac + "  Body=" + _origonalMessage;
;
  }


  return new Results
  {
    Message = compare 
  };
}

public class Results
{
  public string Message {get; set;}
}

Output from the script:

{
  "body": {
    "message": "noMatch: Calc=62c72a210402ffc1cefed5547192fd14e44ef1dfdc012f3279940ab5f35105b8
                         Orig=af9d5fe5216e4a3c731cc864ddc0dba66ae22b68605678fd2a3c381dc5c72025
                         Body={rn  "id": 13,rn  "baseprofile": {rn    "id": 3,rn    "value": "Accountant",rn    "profile": "https://api.icims.com/customers/1234/jobs/3/"rn  },rn  "associatedprofile": {rn    "id": 5,rn    "value": "JohnSmith",rn    "profile": "https://api.icims.com/customers/1234/people/5/"rn  },rn  "status": {rn    "id": "D5432",rn    "value": "InterviewScheduled"rn  },rn  "source": "iCIMS.com",rn  "sourcename": "Internal"rn}"
  }
}

Origonal formated JSON is like this:

{
    "id": 13,
    "baseprofile": {
        "id": 3,
        "value": "Accountant",
        "profile": "https://api.icims.com/customers/1234/jobs/3/"
    },
    "associatedprofile": {
        "id": 5,
        "value": "JohnSmith",
        "profile": "https://api.icims.com/customers/1234/people/5/"
    },
    "status": {
        "id": "D5432",
        "value": "InterviewScheduled"
    },
    "source": "iCIMS.com",
    "sourcename": "Internal"
}

So, how do you compare the local and remote HMAC strings specifically in an Azure Workflow ‘CSharp Script Code’ object calculated on the input body text, whilst preserving the formatting? When looking at the input and output JSON text through Postman the formatting is preserved and the text looks the same.

Any help would be appreciated.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật