This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to convert private key from text to hex value

HI Team,

We have generated the private key from "nrfutil" tool and we want to integrate to our code, how to extract from python generated file "private.key" file to hex value.

Eg:

         -----BEGIN EC PRIVATE KEY-----
MHcCAQEEIJX5obLZDyFEMZtW3BrfvreBI90xu9QmcfdkbKxfvMPhoAoGCCqGSM49
AwEHoUQDQgAEPKntlb897rDjpAp72pkz+Om4MPn7HvUFz9cBNGZzaLGyfM/VO6qf
6ZjW5BrSfsixYNc5D2qaTgJj7zg5ACDONQ==
-----END EC PRIVATE KEY-----

Regards,

Srinivas.V

  • Nrfutil knows a --help argument, which can be used for specific usages, too: "nrfutil.exe keys display --help"

    >nrfutil.exe keys display --key pk compromized_key.pem --format hex
    Public (verification) key pk:
    b16873663401d7cf05f51efbf930b8e9f83399da7b0aa4e3b0ee3dbf95eda93c35ce20003938ef63024e9a6a0f39d760b1c87ed21ae4d698e99faa3bd5cf7cb2
    
    >nrfutil.exe keys display --key pk compromized_key.pem --format code
    
    /* This file was automatically generated by nrfutil on 2020-06-20 (YY-MM-DD) at 16:42:01 */
    
    #include "stdint.h"
    #include "compiler_abstraction.h"
    
    /** @brief Public key used to verify DFU images */
    __ALIGN(4) const uint8_t pk[64] =
    {
        0xb1, 0x68, 0x73, 0x66, 0x34, 0x01, 0xd7, 0xcf, 0x05, 0xf5, 0x1e, 0xfb, 0xf9, 0x30, 0xb8, 0xe9, 0xf8, 0x33, 0x99, 0xda, 0x7b, 0x0a, 0xa4, 0xe3, 0xb0, 0xee, 0x3d, 0xbf, 0x95, 0xed, 0xa9, 0x3c,
        0x35, 0xce, 0x20, 0x00, 0x39, 0x38, 0xef, 0x63, 0x02, 0x4e, 0x9a, 0x6a, 0x0f, 0x39, 0xd7, 0x60, 0xb1, 0xc8, 0x7e, 0xd2, 0x1a, 0xe4, 0xd6, 0x98, 0xe9, 0x9f, 0xaa, 0x3b, 0xd5, 0xcf, 0x7c, 0xb2
    };

    Unfortunately, the private key posted here is now compromized and you must generate a new one. Remember: This forum is public.

  • Hi Turbo,

    Thanks for your reply, what ever you are showing is public key , but we want to see the private key in hex format the way public key shown here instead of text , why means we are testing ecc functionalities with hard coded keys (private/public) in our test app, for that we need this key pair. Originally we are not disclosing the private key.

    Regards,

    Srinivas.V

  • Left as excercise for the readers - see the --help command above. Hint: You need to change ONE character in each example...

Related