My project needs to connect the Azure Cosmo DB by REST API. The Azure Cosmo DB connection requires to pass a HMACSHA256 signature to the HTTP header. I tried to use THashSHA2.GetHMAC(Data, Key) function in Delphi 10.2 to get this signature. In order to verify the result, I run the sample code in C# (downloaded from MS) to verify the result generated by Delphi. Unfortunately, they are not the same! C# : 2LuKbSl8RkLc0eKhjQv4oCpXzRcmR02L9sDfSxSB5HA= Delphi: 2ca409c9a26aa3ed6c772b6bda5bbe66bcd0d929c3ca4359f19ea42314437e5a I verify the Delphi result by the online HMACSHA256 generator. Delphi is correct.
I searched over the web to find another way to generate the signature. I got TIdHMACSHA256 (using IdSSLOpenSSL.LoadOpenSSLLibrary). I tried the code but also no luck. The result (96OyCOmXzODAP9CljJgleuG5J5c4nIDeiSlr3hdcpYY=) is also not the same as the one generated by C#.
I noticed that C# code run Convert.FromBase64String(key) to convert the key to byte, generate the hash and then Convert.ToBase64String(hashPayLoad) to signature. I suspect the wrong result in Delphi is missing this kind of steps. But I do not know how to do it.
Do anyone have experience generating Azure Cosmo DB signature by Delphi? Please help!