TLV Base64 in QR Code for ZATCA E-Invoicing

Barcode Information | Tutorials | Examples

Tag-Length-Value (TLV) is a method of encoding fields of data within a single string of data or a barcode symbol. Base64 is a method of encoding a string of data, which makes the text that is encoded appear encrypted. Base64 conversion is also used to support the encoding of Unicode characters, such as Arabic text, with systems such as barcode scanners that cannot otherwise support these characters. It is a requirement per KSA Zakat, Tax and Customs Authority (ZATCA) of Saudi Arabia to encode e-invoicing fields in TLV format and then encode that string in Base64 within a QR Code.

The following is a simple overview of this process:

  1. Obtain the fields of data to encode
  2. Calculate TLV values before each field of data
  3. Combine the fields and TLV values into a single string
  4. Convert the string to Base64
  5. Encode the result in a QR Code symbol

Below is a TLV Base-64 encoded QR Code invoice example that includes UTF-8 Unicode characters.

TLV Base-64 encoded QR Code invoice example

A standard scanner will show the base64 string of data that is encoded. The data can be better examined and tested with the IDAutomation Data Decoder Verifier App. TLV values are shown in Hexadecimal before each field. The app also verifies that the TLV fields are encoded correctly. The scan result will decode the base64 string and show the tag (field number) and the length (length of the next field) and the value (the data in the field).

TLV Base64 tested with the IDAutomation Data Decoder Verifier App

IDAutomation offers an enhanced encoding ability to support TLV with and without Base64 in QR Code for products updated in 2022 or later. The following options are available when the ApplyTilde or ProcessTilde option is enabled.

  • Encode TLV into Base64: This allows TLV fields to be encoded in Base64 when the first character is | and the fields are separated by |
    Example: |IDAutomation|123456789012345|2022-11-30 06:04:31|92435.33|2692.22
  • Encode TLV Only: When the first two characters are ^| TLV values separated by | are encoded.
    Example: ^|IDAutomation|123456789012345|2022-11-30 06:04:31|92435.33|2692.22
  • Encode Base64 Only. When the first character is “=” all data is encoded in Base64.
    Example: =This text is encoded in Base-64

Supported Products

This capability is supported in all IDAutomation QR Code product versions 2022 or later including: