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

Community site session details

Session Id :

Business Central 365: Cryptography Management (Hashing with Codeunit 1266)

Khushbu Rajvi. Profile Picture Khushbu Rajvi. 20,147 Super User 2025 Season 2

In today’s post, let’s explore one of the most interesting and often overlooked areas of Microsoft Dynamics 365 Business Central — the Cryptography Management (Codeunit 1266).

This codeunit empowers developers to perform hashing and encryption operations directly within AL code, enabling scenarios such as secure data storage, integrity validation, and password handling — all without relying on external libraries or custom .NET integrations.

The Cryptography Management codeunit provides multiple procedures for managing hashing and symmetric encryption.

👉 In this post, we’ll focus on the GenerateHash procedure, which allows you to create hash values using popular algorithms like MD5, SHA1, SHA256, SHA384, and SHA512.

Understanding the GenerateHash Procedure

Purpose:
The GenerateHash function creates a unique hash value from any text you provide.
You can choose from several hashing algorithms such as MD5, SHA1, SHA256, SHA384, and SHA512.

Parameters:

  • InputString: The text or value you want to convert into a hash.
  • HashAlgorithmType: The algorithm you want to use (MD5, SHA1, SHA256, SHA384, or SHA512).

Returns:
A hexadecimal string that represents the hashed value of your input.

What is Hashing?

Hashing is a one-way process that changes your input text into a fixed-length string of characters.
Once hashed, the original text cannot be reversed or recovered — making it useful for secure storage and validation.

Example of Hash Algorithms

AlgorithmHash LengthDescription
MD5128 bitsFast but outdated
SHA1160 bitsOlder, less secure
SHA256256 bitsCommon and secure choice
SHA384384 bitsStronger security level
SHA512512 bitsVery strong and longest output

Below is a practical example page that uses the Cryptography Management

codeunit to generate hashes for different algorithms.

page 50121 "MyPage Cryptography"
{
    PageType = Card;
    ApplicationArea = All;
    UsageCategory = Administration;
    Caption = 'My Cryptography Page';

    layout
    {
        area(Content)
        {
            group(General)
            {
                field("Name"; NameSource)
                {
                    ApplicationArea = All;
                    ToolTip = 'Enter some text to hash/encrypt.';
                }
            }
        }
    }

    actions
    {
        area(Processing)
        {
            action("Show Hashes")
            {
                ApplicationArea = All;
                Caption = 'Show Hashes';

                trigger OnAction()
                var
                    CryptoMgt: Codeunit "Cryptography Management";
                    HashAlg: Option MD5,SHA1,SHA256,SHA384,SHA512;
                    plain: Text;
                    md5Txt: Text;
                    sha1Txt: Text;
                    sha256Txt: Text;
                    sha384Txt: Text;
                    sha512Txt: Text;
                begin
                    // Take text from the page field; fallback if empty
                    plain := NameSource;

                    md5Txt := CryptoMgt.GenerateHash(plain, HashAlg::MD5);
                    sha1Txt := CryptoMgt.GenerateHash(plain, HashAlg::SHA1);
                    sha256Txt := CryptoMgt.GenerateHash(plain, HashAlg::SHA256);
                    sha384Txt := CryptoMgt.GenerateHash(plain, HashAlg::SHA384);
                    sha512Txt := CryptoMgt.GenerateHash(plain, HashAlg::SHA512);

                    Message(
                      'Input: %1\MD5: %2\SHA1: %3\SHA256: %4\SHA384: %5\SHA512: %6',
                      plain, md5Txt, sha1Txt, sha256Txt, sha384Txt, sha512Txt);
                end;
            }
        }
    }

    var
        NameSource: Text[250];
}


Output:

Each algorithm generates a unique hash for the same text input, varying in size and security strength.

With just a few lines of AL code, you can securely hash and validate any piece of text.
The built-in Cryptography Management codeunit makes it seamless for Business Central developers to implement modern cryptographic functions without needing external libraries.

Stay tuned — in the next post, we’ll explore Cryptography in Business Central and learn how to safely encrypt and decrypt data strings 🔐✨


Thanks For Reading...!!


Regards,

Khushbu Rajvi


This was originally posted here.

Comments

*This post is locked for comments