> For the complete documentation index, see [llms.txt](https://developer.magtek.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.magtek.com/api-and-command-reference/dynafamily-programmers-manual/commands/0xennn-security/0xef01-load-key-using-tr-31.md).

# 0xEF01 - Load Key Using TR-31

The host uses this command to load a key into one of several available slots in the device’s secure memory.

## Device Key ID / Slot

| ID   | Label     | Description                       | Load TK |
| ---- | --------- | --------------------------------- | ------- |
| 1000 | TMPTK     | Temporary KBPK                    | agree   |
| 1001 | MTK       | Master Transport                  | TMPTK   |
| 1002 | DEVTK     | Device Master                     | MTK     |
| 1003 | FINTK     | Financial Master                  | MTK     |
| 1021 | PRODTK    | Production - MagTek Internal Only | DEVTK   |
| 1022 | MFGTK     | MagTek Only Internal/External     | DEVTK   |
| 1081 | MKIFTK    | MagTek KIF Financial Keys         | FINTK   |
| 1101 | FREQMK    | Factory Request MAC               | PRODTK  |
| 1102 | MREQMK    | Mfg Device Request MAC            | MFGTK   |
| 1111 | MFRQMK    | Mfg Financial Request MAC         | MKIFTK  |
| 20xx | DKPTM0-1F | MagTek DUKPT Initial Key          | MKIFTK  |

To inject a specific key in the above table, the corresponding Load TK shall be injected previously.

As shown in the table, MTK injection requires that a TMPTK has been created. See [<mark style="color:red;">**Command 0xF017 - Establish Ephemeral KBPK**</mark>](https://developer.magtek.com/api-and-command-reference/dynafamily-programmers-manual/commands/0xfnnn-manufacturing/0xf017-establish-ephemeral-kbpk).

After MTK has been injected successfully, the sequence of injecting other keys is as follows:

{% stepper %}
{% step %}

### Establish a secure session (Get Challenge)

The host uses [<mark style="color:red;">**Command 0xE001 - Get Challenge**</mark>](https://developer.magtek.com/api-and-command-reference/dynafamily-programmers-manual/commands/0xennn-security/0xe001-get-challenge) to establish a secure session with the device.
{% endstep %}

{% step %}

### Construct TR-31 key block

The host constructs a TR-31 (X9.143) key block for the key it is going to load. (Note that the Load Key must be injected previously.)
{% endstep %}

{% step %}

### Construct command request

The host constructs the command request for [<mark style="color:red;">**Command 0xEF01 - Load Key Using TR-31**</mark>](https://developer.magtek.com/api-and-command-reference/dynafamily-programmers-manual/commands/0xennn-security/0xef01-load-key-using-tr-31) in the format below.
{% endstep %}

{% step %}

### Send the command

The host sends the command request to the device.
{% endstep %}

{% step %}

### Device response

The device sends a response in the format below to the host.
{% endstep %}
{% endstepper %}

## Load Key Using TR-31 - Request Data for Command 0xEF01

<table><thead><tr><th>Tag</th><th width="76.33331298828125">Len</th><th width="243">Value / Description</th><th width="76">Typ</th><th width="77.6666259765625">Req</th><th width="98.6666259765625">Default</th></tr></thead><tbody><tr><td>Beginning of any wrappers, at minimum including <strong>Request Message</strong> </td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>EF01 = <strong>Load Key Using TR-31 - Command 0xEF01</strong> </td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>84</td><td>var</td><td>Key Block — This is a populated, secured <a href="https://developer.magtek.com/api-and-command-reference/dynafamily-programmers-manual/data-types-and-shared-tlv-data-objects/mifare-card-data-type-emv-contactless-only"><mark style="color:red;"><strong>MIFARE Card Data Type (EMV Contactless Only)</strong></mark> </a></td><td>B</td><td>R</td><td></td></tr><tr><td>DFDFDF40</td><td>var</td><td>MIFARE Card Data in ASCII terminated with NULL character</td><td></td><td></td><td></td></tr><tr><td>DFDFDF41</td><td>var</td><td>MIFARE Card Data in Binary (optional)</td><td></td><td></td><td>O</td></tr><tr><td>TR-31 Key Block Type.</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>End of any wrappers, at minimum including <strong>Request Message</strong></td><td></td><td></td><td></td><td></td><td></td></tr></tbody></table>

## Load Key Using TR-31 - Response Data for Command 0xEF01

<table><thead><tr><th width="241">Tag</th><th width="75">Len</th><th>Value / Description</th><th width="73.66668701171875">Typ</th><th width="75.333251953125">Req</th><th width="98">Default</th></tr></thead><tbody><tr><td>Beginning of any wrappers, at minimum including <strong>Response Message</strong> </td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>EF01 = <strong>Load Key Using TR-31 - Command 0xEF01</strong> </td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>No parameters.</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>End of any wrappers, at minimum including <strong>Response Message</strong> </td><td></td><td></td><td></td><td></td><td></td></tr></tbody></table>

#### Request Example&#x20;

{% code title="Example (Hex)" %}

```
AA 00 81 04 01 1A EF 01 84 82 01 36 EF 01 84 82 01 30 44 30 33 30 34 42 31 54 58 30 30 
4E 30 36 30 30 49 4B 31 38 46 46 46 46 39 38 37 36 35 34 33 32 31 30 33 30 30 30 30 30 
32 31 35 38 4D 47 54 4B 31 30 30 31 54 31 31 30 34 32 30 30 37 31 32 30 34 31 30 38 31 
32 31 30 34 30 30 33 46 33 31 30 37 42 35 30 41 46 44 32 33 32 31 30 43 39 33 36 31 39 
44 44 41 41 32 31 33 36 43 37 33 33 31 30 32 30 32 30 31 32 30 34 54 31 37 31 36 33 30 
5A 4B 50 30 45 30 31 39 33 36 46 41 33 32 45 4B 43 30 41 30 30 34 35 30 30 54 53 31 34 
32 30 32 30 30 39 30 32 54 31 35 35 38 30 32 5A 50 42 30 34 35 37 32 31 37 46 33 34 37 
31 34 43 32 42 38 38 46 33 39 35 35 32 32 32 46 46 35 39 41 41 30 35 37 44 39 39 41 46 
38 32 41 37 35 37 32 46 39 33 38 46 38 33 38 42 43 36 35 45 45 35 34 46 39 34 37 46 35 
39 41 30 36 43 44 34 35 35 31 39 32 32 37 41 32 35 35 43 37 44 35 44 37 43 38 36 37 34 
35 30 33 46 41 43 36 46 41 37 31 33 32 43 38 46 41 39 39 36 42 34 45 42 36 41 41 31 31 
34 46 45
```

{% endcode %}

#### Response Example&#x20;

{% code title="Response Example (Hex)" %}

```
AA 00 81 04 82 1A EF 01 82 04 00 00 00 00
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developer.magtek.com/api-and-command-reference/dynafamily-programmers-manual/commands/0xennn-security/0xef01-load-key-using-tr-31.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
