Dynamics 365 Business Central – Cryptography Management
November 29, 2019
With release of version 4.0 Business Central 2019 wave 2, the existing encryption and hashing functions are moved to a separate codeunit called 1266 Cryptography Management.
It has different functions for:
- Data Encryption and Decryption
- To generate hash for different hashing algorithms from a string or stream. It supports hashing algorithms like MD5, SHA1, SHA256, SHA384, SHA512
- To generate base64 encoded hash from string. Again, it supports MD5, SHA1, SHA256, SHA384, SHA512 hashing algorithms
- To generate a key base64 encoded hash from a string based on the provided hash algorithm and key.
Here is the sample code on how to MD5 hash for the string value. Generally, we need to pass MD5 hash of password / login credentials while consuming API of the external applications.
procedure MD5Hash(Pwd:Text): Text
var
CryptographyManagement: Codeunit “Cryptography Management”;
HashAlgorithmType: Option MD5,SHA1,SHA256,SHA384,SHA512;
begin
//Returns MD5 Hash of input string. Based on the requirement we can have options to use different hashing algorithms
exit(CryptographyManagement.GenerateHash(Pwd, HashAlgorithmType::MD5));
end;

Written By
Rachlin Thomas
Sr. Software Developer