Identity key generation

This sample demonstrates how to generate a random device-specific identity using Identity key, which is then stored in the Key Management Unit (KMU).


The following development kits are supported:

Hardware platforms


Board name

Build target

nRF9160 DK




nRF5340 DK




The Hardware unique key library is required to generate and store the prerequisite Master Key Encryption Key (MKEK) into KMU.


Once the required identity key is provisioned on the device, only the code pages should be erased as ERASEALL removes the identity key from the system.


The identity key is stored in the KMU in encrypted form using the Hardware Unique Key (HUK) Master Key Encryption Key (MKEK). The sample also demonstrates how to generate a random MKEK and store it in KMU.

The sample performs the following operations:

  1. The random hardware unique keys(HUKs) are generated and stored in the KMU.

  2. A random identity key of type secp256r1 is generated and stored in the KMU.

  3. The identity key is verified to be stored in KMU.


See Configuring your application for information about how to permanently or temporarily change the configuration.

Building and running

This sample can be found under samples/keys/identity_key_generate in the nRF Connect SDK folder structure.

To build the sample with Visual Studio Code, follow the steps listed on the How to build an application page in the nRF Connect for VS Code extension documentation. See Building and programming an application for other building and programming scenarios and Testing and debugging an application for general information about testing and debugging in the nRF Connect SDK.


After programming the sample to your development kit, complete the following steps to test it:

  1. Connect to the kit that runs this sample with a terminal emulator (for example, PuTTY). See How to connect with PuTTY for the required settings.

  2. Reset the kit.

  3. Observe the following output:

    Generating random HUK keys
    Writing the identity key to KMU

    If an error occurs, the sample prints a message and raises a kernel panic.


The following libraries are used: