Skip to main content

Posts

Showing posts with the label kotlin

The QCAT Standard: Understanding Byte Encodings for Length Representation

In programming, it’s common to deal with lengths or sizes of data. Depending on the size of that data, we represent its length using bytes. But how exactly does this encoding work? Let’s break it down step by step. What is a Byte? A  byte  is a unit of data that consists of 8  bits . Each bit is a binary value, meaning it can either be a  0  or a  1 . For example, if we have a sequence of 8 bits, it might look like this: 00000000 That’s a byte with all zeroes. How We Encode Lengths Using Bytes When encoding a length in bytes, we need to consider how large that length is. The larger the number, the more bytes we need to represent it. Let’s look at an example to make this clearer. Example 1: Length = 255 Let’s say we have the value  255 , and we want to encode this length in bytes. Since  255  can fit in 1 byte (8 bits), it’s simple. The binary representation of  255  is: 11111111 This is the maximum value you can store in a single by...

The QCAT Standard: Generating the QR Code

In this guide, we’ll explore how to generate the QCAT QR code by creating a custom TLV (Tag-Length-Value) structure in Kotlin. TLV encoding is commonly used in QR codes, smart cards, and other systems where data must be serialized into a compact, structured format. We'll also discuss encoding techniques, including converting date-times, durations, and ASCII values into hex format. Overview of the Code This Kotlin code focuses on generating a TLV structure that encodes various data fields such as a ticket ID, creator ID, creation timestamp, and a validity period into a hex-based format. Finally, it converts the TLV structure into a Base64 encoded string for easy transmission. The structure involves the following major steps: Hex Conversion: Converting data types like date-time, durations, and ASCII strings to hexadecimal. TLV Encoding: Wrapping each piece of data with a tag, its length, and value. Serialization: Serializing the data and converting it to a byte array for encoding....

The QCAT Standard: Implementing Public Key Management System for QR Code Signing

In this guide, we’ll explore how to implement a Public Key Management System for signing QR codes, focusing on the QCAT Signature Algorithms Version 1 and 2. Key Management Overview The QR Code signature system relies on cryptographic keys and certificates to ensure the authenticity of the QR codes generated by issuers. The key players in this system are the Certificate Authority (CA) and the QR Code Ticket Issuers. 1. Certificate Authority (CA) : The CA signs the issuer’s public keys using its private key, creating a public key certificate. This certificate ensures the QR codes can be verified at validation terminals. CA uses a 2048-bit RSA key to sign the issuer’s keys, ensuring a high level of security. 2. Ticket Issuer : Each issuer generates their own public/private key pairs. The private key is used to sign QR codes, while the public key is included in the certificate signed by the CA. Validation terminals use the issuer’s public key to verify the signature on a QR code. 3. Valid...

How to Convert Data Types to Hexadecimal in Kotlin?

Hexadecimal is a base-16 number system commonly used in programming for its concise representation of binary values. Converting various data types to hexadecimal format can be particularly useful in scenarios like memory addressing, color representation, and data serialization. In this article, we will explore how to convert different data types to hexadecimal in Kotlin, complete with practical examples. Understanding Hexadecimal Hexadecimal (often abbreviated as hex) uses sixteen symbols: 0-9 represent values zero to nine, and A-F represent values ten to fifteen. This representation allows for more compact notation compared to binary (base-2) or decimal (base-10) systems. For example, the decimal number 255 is represented as FF in hexadecimal. Comparison of Number Systems: Decimal Binary Hexadecimal 10 1010 A 15 1111 F 255 11111111 F...