web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to use HMACSHA256 in F&O

(1) ShareShare
ReportReport
Posted on by 3,045
Hi,
 
I have a requirement where I need to generate the authentication signature using .Net class HMACSHA256. Does any one know how we can use this in x++. I have key and data using these values we have to generate hexa signature.
I have the same question (0)
  • Hana Xue Profile Picture
    Microsoft Employee on at
    Hi,
    Before the developer offers professional advice, hopefully the following link will be helpful.
    GitHub - hadmacker/HmacSignature: HMAC SHA256 Signature implementation using .NET Core and xUnit
    Best Regards,
    Hana
  • Suggested answer
    Martin Dráb Profile Picture
    238,143 Most Valuable Professional on at
    You can use System.Security.Cryptography.HMACSHA256 class via .NET Interop. It's included in the .NET Framework.
  • Pooja Karki Profile Picture
    3,045 on at
    Hi,
     
    Thanks for response I have refered both link and written below code and getting below output in X++.  I am not sure what wrong I was doing.
     
    Code output: "System.Byte[]"
     
    str key, data;
    System.Text.StringBuilder sBuilder;
    ClrObject obj;
    str signature;
    key='67be6c44----a34fa4f1abb6';
    data='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    System.Security.Cryptography.HMACSHA256 hmac=new System.Security.Cryptography.HMACSHA256();
    hmac.Key=System.Text.Encoding::UTF8.GetBytes(key);
    hmac.ComputeHash(System.Text.Encoding::UTF8.GetBytes(data));
    obj=hmac.Hash;
    sBuilder = new System.Text.StringBuilder();
    sBuilder.Append(obj);
    signature=sBuilder.ToString();
    info(strFmt("%1",signature));
  • Martin Dráb Profile Picture
    238,143 Most Valuable Professional on at
    You seem to implicitly convert a byte array to string, which calls ToString() method of the array and it gives you this result.
     
    First of all, ask yourself whether you need to convert the hash to a string at all. If so, think about how you want to convert it. Then write code doing that.
  • Verified answer
    Pooja Karki Profile Picture
    3,045 on at
    Thanks for suggestion , I am able to generate signature using below code.
     
    str key, data;
    System.Text.StringBuilder sBuilder;
    System.Array resultByteArray;
    int arrayLength ;
    ClrObject clrStrObject;
    ClrObject clrStr;
    int i;
    str signature;
    key='67be6c44----a34fa4f1abb6';
    data='xxxxxxxxxxxxxxxxxxxx';
    System.Security.Cryptography.HMACSHA256 hmac=new System.Security.Cryptography.HMACSHA256();
    hmac.Key=System.Text.Encoding::UTF8.GetBytes(key);
    resultByteArray=hmac.ComputeHash(System.Text.Encoding::UTF8.GetBytes(data));
    sBuilder = new System.Text.StringBuilder();
    arrayLength = resultByteArray.get_Length() ;
    for (i = 0; i <arrayLength; i++)
    {
        clrStrObject = resultByteArray.GetValue(i);
        clrStr = clrStrObject.ToString('x2');
        sBuilder.Append(clrStr);
    }
    signature = sBuilder.ToString();
    info(strFmt("%1",signature));
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 679 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 410 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 292 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans