Here is a simple way to calculate SHA256 hashes with Microsoft Dynamics NAV 2013.

(There is a easier way if you’re using NAV2018 – Read here)

Download the Microsoft Dynamics NAV 2013 object here: SHA256

3 Responses

  1. Hi, thanks for the SHA256 code. I think I may be misusing it, I’m trying to create a signature for Amazon Web Services, ( as below (first step). Any help would be greatly appreciated. Thanks Roddy

    Test Input
    dateStamp = ‘20120215’

    Expected Output
    kDate = ‘969fbb94feb542b71ede6f87fe4d5fa29c789342b0f407474670f0c2489e0a0d’

    Actual Output
    kDate = ‘8583c661110d4c95a37df70fd6f70d92fd18418f306c9f8d54582a2c354acad4”

    Sample Psuedo code from AWS
    kDate = HMAC(“AWS4” + key, dateStamp) //UTF-8

    My use of your library
    SHA256Lib.AddString(AsciiAnsiLib.Ansi2Ascii(‘AWS4’ + key));
    kDate := SHA256Lib.CalculateSHA256;

    1. You cannot use SHA256 for HMACSHA256 – see

      You much recreate this C# example from Amazon in C/AL

      static byte[] HmacSHA256(String data, byte[] key)
      String algorithm = "HmacSHA256";
      KeyedHashAlgorithm kha = KeyedHashAlgorithm.Create(algorithm);
      kha.Key = key;

      return kha.ComputeHash(Encoding.UTF8.GetBytes(data));

      static byte[] getSignatureKey(String key, String dateStamp, String regionName, String serviceName)
      byte[] kSecret = Encoding.UTF8.GetBytes(("AWS4" + key).ToCharArray());
      byte[] kDate = HmacSHA256(dateStamp, kSecret);
      byte[] kRegion = HmacSHA256(regionName, kDate);
      byte[] kService = HmacSHA256(serviceName, kRegion);
      byte[] kSigning = HmacSHA256("aws4_request", kService);

      return kSigning;

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.