| Offset | Size | Description | Example |
| 0x0 | 0x20 | MAGIC ("keystone") and some constant bytes | 6b 65 79 73 74 6f 6e 65 02 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 0x20 | 0x20 | HMAC-SHA256 (32 bytes) of the bytes of the passcode using keystone_passcode_secret as key | - |
| 0x40 | 0x20 | HMAC-SHA256 (32 bytes) of the previous two sections using keystone_ks_secret as key | - |
public static byte [] GenerateKeystoneFile (string passcode)
{
// 1. The first 32 bytes are constant
byte[] keystone = {
0x6B, 0x65, 0x79, 0x73, 0x74, 0x6F, 0x6E, 0x65, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 2. Convert the 32 characters of the passcode to a byte array
byte[] passcodeInHEX = Encoding.ASCII.GetBytes(passcode);
// 3. Calculate the...