Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

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

Posted on by Microsoft Employee

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,

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

    Did you solve it?

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,696 Super User 2024 Season 2 on at
    RE: How to encode Tag-Length-Value (TLV) string into base64

    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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to encode Tag-Length-Value (TLV) string into base64

    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

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

    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
    Community Member Microsoft Employee on at
    RE: How to encode Tag-Length-Value (TLV) string into base64

    .....

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to encode Tag-Length-Value (TLV) string into base64

    @YUN ZHU

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to encode Tag-Length-Value (TLV) string into base64

    Anyone can help me ?!

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans