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

Announcements

No record found.

News and Announcements icon
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
    239,040 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
    239,040 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

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 658

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 468 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 333 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans