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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

How to encode Tag-Length-Value (TLV) string into base64

(0) ShareShare
ReportReport
Posted on by

Hello , 



For those who don't know what TLV is:

Type/Tag-Length-Value (TLV) is an encoding scheme used in many communication protocols to encode data. A TLV-encoded message has a defined structure that consists of 3 sections/parts. Those are:
● Code of the message type (T) - 1 Byte fixed sizes of 1 byte (2 digits)
● Message value length (L) - 1 Byte fixed sizes of 1 byte (2 digits)
● Message value itself. (V) - Variable (variable size) includes the result of encoding the text string into hexadecimal

The coming example shows a string of TLV and the required result of encoding it into base64:

Example of a TLV:

01 15 42 6f 62 73 20 42 61 73 65 6d 65 6e 74 20 52 65 63 6f 72 64 73 02 0f 31 30 30 30 32 35 39 30 36 37 30 30 30 30 33 03 14 32 30 32 32 2d 30 34 2d 32 35 54 31 35 3a 33 30 3a 30 30 5a 04 0a 32 31 30 30 31 30 30 2e 39 39 05 09 33 31 35 30 31 35 2e 31 35

Encode this to a Base64 must represent:

ARVCb2JzIEJhc2VtZW50IFJlY29yZHMCDzEwMDAyNTkwNjcwMDAwMwMUMjAyMi0wNC0yNVQxNTozMDowMFoECjIxMDAxMDAuOTkFCTMxNTAxNS4xNQ==

Now, the question is, how to encode the previous TLV string into base64 programmatically in (AL) to get the base64 string shown above??

I hope my question is clear and thank you in advance for your support.

Regards,

I have the same question (0)
  • Community Member Profile Picture
    on at

    Anyone can help me ?!

  • Community Member Profile Picture
    on at

    @YUN ZHU

  • Community Member Profile Picture
    on at

    .....

  • Lars Lohndorf-Larsen Profile Picture
    on at

    Hello,

    How about this - using codeunit "Base64 Convert":

    codeunit 50110 MyCodeunit

    {

       trigger OnRun()

       begin

           MyTlv :=

             '01 15 42 6f 62 73 20 42 61 73 65 6d 65 6e 74 20 52 65 63 6f 72 64 73 02 0f 31 30 30 30 32 35 39 30 36 37 30 30 30 30 33 03 14 32 30 32 32 2d 30 34 2d 32 35 54 31 35 3a 33 30 3a 30 30 5a 04 0a 32 31 30 30 31 30 30 2e 39 39 05 09 33 31 35 30 31 35 2e 31 35';

           Myhash := Base64.ToBase64(MyTlv);

           message(MyHash);

       end;

       var

           CryptoMgt: Codeunit "Cryptography Management";

           Base64: Codeunit "Base64 Convert";

           MyTlv: Text;

           MyHash: Text;

    }

    There is another codeunit "Cryptography Management" which may also be of use there.

    Would that work for you, or was that too easy :-) ?

  • Community Member Profile Picture
    on at

    I'm trying to convert to base64,

    the format base64 it's not fetching the result as shown above.

    I need the same format to compatible with Saudi e-invoice  , ZATCA On QR Code

  • Suggested answer
    YUN ZHU Profile Picture
    95,597 Super User 2025 Season 2 on at

    Hi, I'm sorry I haven't tested it, but I hope the following information can give you some help.

       

    Another C# sample

    https://stackoverflow.com/questions/70260145/saudi-arabia-e-invoicing-qr-code-tlv-with-base64-encoding-in-c-sharp

    Thanks.

    ZHU

  • mohamed gamal Profile Picture
    on at

    Did you solve it?

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

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,917

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,161 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,025 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans