How to USe HMAC authentication in NAv 2016

Hi Team,

I am trying to consume API which use Hmac authentication. i am trying to convert below C# Code to CAL code…could you please help me to do so

C# Code
static String createSignature(String signingBase, String secretKey) {
byte k = System.Text.ASCIIEncoding.UTF8.GetBytes(secretKey);
HMACSHA256 myhmacsha256 = new HMACSHA256 (k);
Byte dataToHmac = System.Text.Encoding.UTF8.GetBytes(signingBase);
string signature = Convert.ToBase64String(myhmacsha256.ComputeHash(dataToHmac));
return signature;

NAV CAL Code

BytesK:=Encoding.ASCII.UTF8.GetBytes(SecrectKey_);
Crypto:=Crypto.HMACSHA256.Create();
Crypto.Key:=BytesK;
DatatoHmac:=Encoding.UTF8.GetBytes(SignBase);
HmacSH1Signature:=Convert.ToBase64String(Crypto.ComputeHash(DatatoHmac));

Variables

Name DataType Subtype Length
DatatoHmac DotNet System.Array.‘mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’
Crypto DotNet System.Security.Cryptography.HMACSHA256.‘mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’
HmacSignature Text
Encoding DotNet System.Text.UTF8Encoding.‘mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’
Convert DotNet System.Convert.‘mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’
BytesK DotNet System.Array.‘mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’

Thanks
Sachin

Here is the NAV CAL code for converting the given C# code to CAL code:

HmacSignature@CREATE();
DatatoHmac@SET(Encoding.UTF8.GetBytes(SigningBase));
BytesK@SET(Encoding.ASCII.GetBytes(SecretKey_));

Crypto@SET(Crypto.HMACSHA256.Create());
Crypto.Key@SET(BytesK);

HmacSignature@SET(Convert.ToBase64String(Crypto.ComputeHash(DatatoHmac)));

In this code, we first create a new instance of the HmacSignature object. We then set the value of the DatatoHmac variable to the bytes of the signingBase string encoded in UTF-8. Similarly, we set the value of the BytesK variable to the bytes of the secretKey string encoded in ASCII.

Next, we create a new instance of the HMACSHA256 object and set its Key property to the value of the BytesK variable. Finally, we set the value of the HmacSignature variable to the base64-encoded string representation of the hash of the DatatoHmac variable using the ComputeHash method of the Crypto object.

This code should produce the same result as the given C# code for creating an HmacSHA256 signature.