I am building an inhouse Invoicing solution for my company. The government requires us to create QR Code fields encoded in Tag-Length-Value (TLV) format.
The TLV encoding shall be as follows:
Tag: the tag value as mentioned above stored in one byte
Length: the length of the byte array resulted from the UTF8 encoding of the field value. The length shall be stored in one byte.
Value: the byte array resulting from the UTF8 encoding of the field value.
In the example they have provided this Base64 Output
AQkxMjM0NTY3ODkCCjEyLzEyLzIwMjADBDEwMDADAzE1MPaIn2Z2jg6VqWvWV6IrZZNzLF7xvZrWXW5xRV5yFY2xFu0ycXOiyqV0k7Wsh6b1IcE2Tfzap1AQAQVsktmsv1FFQ1MxIAAAAGKblFMh9nFRSn8tvftXqo9zRSz2VEAPITSZ3W7UDHKhUx+7yXGijLtJSZGXMOc+jpKwARzDl68GmmRd75NWdOs=
When I decode using
$base64 = "AQkxMjM0NTY3ODkCCjEyLzEyLzIwMjADBDEwMDADAzE1MPaIn2Z2jg6VqWvWV6IrZZNzLF7xvZrWXW5xRV5yFY2xFu0ycXOiyqV0k7Wsh6b1IcE2Tfzap1AQAQVsktmsv1FFQ1MxIAAAAGKblFMh9nFRSn8tvftXqo9zRSz2VEAPITSZ3W7UDHKhUx+7yXGijLtJSZGXMOc+jpKwARzDl68GmmRd75NWdOs=";
echo base64_decode($base64);
The response i get is:
123456789
12/12/20201000150���fv���k�W�+e�s,^��]nqE^r���2qs�ʥt������!�6M�ڧPl�٬�QECS1 b��S!�qQJ-��W��sE,�T@!4��n�r�S��q���II��0�>���×��d]�Vt�
Tag 1: Seller's Name
Tag 2: Vat Registration number
Tag 3: Timestamp of the invoice
Tag 4: Invoice Total
Tag 5: Tax Total
Tag 6: Hash of XML invoice
Tag 7: ECDSA Signature
Tag 8: ECDSA Public Key
Tag 9: ECDSA signature of the cryptographic stamp’s public key
What Am I doing wrong here and what is the right syntax to correct it?