Sample code and data for generating secure messages
Refer to the sample data and code provided here, when you develop a function to embed in beacon devices to generate secure messages. For the algorithm information on secure message generation, see Generate a secure message.
Sample data
The series of tables show sample data required to generate secure messages and the resulting values when you compute the data correctly. Compare with the data provided here to see if your function for secure message generation behaves properly.
Here are the parameters we'll use to compute secure messages:
| Field | Value |
|---|---|
| HWID | 01deadbeef |
| Vendor key | 5cf2a423 |
| Lot key | 8c194fe41d7fe34f |
| Battery level | 0x01 |
Convert the value of each HWID, vendor key, and lot key to a byte array before calculation.
Timestamp is zero
The timestamp value 0 means that the device is powered on for the first time.
| dummy | dummy |
|---|---|
| Input value | 000000000000000001deadbeef5cf2a4238c194fe41d7fe34f01 |
| SHA-256 hash value | 72de7eafe33a44f0094283e03c28ff8bf85230825616fa49b73edaa6be88a0a8 |
| Message authentication code | 037cf6f1 |
| Secure message | 037cf6f1000001 |
Timestamp is one
The timestamp value 1 means that 15 seconds have passed since the initial power-on.
| dummy | dummy |
|---|---|
| Input value | 000000000000000101deadbeef5cf2a4238c194fe41d7fe34f01 |
| SHA-256 hash value | eba4633c394cf7d913a863f25e930e7b8d9227bd109c2019d9dfbb411366cc4f |
| Message authentication code | c86489c6 |
| Secure message | c86489c6000101 |
Timestamp is 65535
If the timestamp value is incremented from 65535 to 65536, the masked timestamp in the secure message is reset to 0000. See also the Timestamp is 65536 section and check that the masked timestamp changes from ffff to 0000.
| dummy | dummy |
|---|---|
| Input value | 000000000000ffff01deadbeef5cf2a4238c194fe41d7fe34f01 |
| SHA-256 hash value | f435f408d2978130607a8af69da2e6f65b66c260796f03ce2a7daf9b468ae0b5 |
| Message authentication code | 958497b8 |
| Secure message | 958497b8ffff01 |
Timestamp is 65536
When the timestamp value is incremented to 65536, the masked timestamp in the secure message is reset to 0000. See also the Timestamp is 65535 section and check that the masked timestamp changes from ffff to 0000.
| dummy | dummy |
|---|---|
| Input value | 000000000001000001deadbeef5cf2a4238c194fe41d7fe34f01 |
| SHA-256 hash value | 70b58ab690b63d519caf37359ce3d910e8e1d79a90f095462ee2d56ae0f035e4 |
| Message authentication code | 564cfb90 |
| Secure message | 564cfb90000001 |
Timestamp is 9223372036854775807
The value 9223372036854775807 is the maximum value of a signed 64-bit integer.
| dummy | dummy |
|---|---|
| Input value | 7fffffffffffffff01deadbeef5cf2a4238c194fe41d7fe34f01 |
| SHA-256 hash value | c626232a199b163c53ba70f4d493c8b34891532d9e8fbf2b788e7e1cf3d13dec |
| Message authentication code | 05d522a7 |
| Secure message | 05d522a7ffff01 |
Timestamp is 18446744073709551615
The value 18446744073709551615 is the maximum value of an unsigned 64-bit integer.
| dummy | dummy |
|---|---|
| Input value | ffffffffffffffff01deadbeef5cf2a4238c194fe41d7fe34f01 |
| SHA-256 hash value | 53ab6c6874fc333398ae2186eb45ce5d5a77d10cd2d3fe3d933a12b33cb13090 |
| Message authentication code | 7393bd92 |
| Secure message | 7393bd92ffff01 |
Sample code
This sample Java code generates a secure message.
This sample code tests the code above, that generates a secure message, with the data from the sample data section.