<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>I like to convert private key to code.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/45804/i-like-to-convert-private-key-to-code</link><description>Hello, 
 I generate a private key by using nrfutil. 
 I like to convert raw data format to use in the code from private key. 
 Additionally, I already used a nrf_crypto_ecc_key_pair_generate() function to generate private key. 
 But, I don&amp;#39;t know how</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 03 May 2019 13:34:33 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/45804/i-like-to-convert-private-key-to-code" /><item><title>RE: I like to convert private key to code.</title><link>https://devzone.nordicsemi.com/thread/185207?ContentTypeID=1</link><pubDate>Fri, 03 May 2019 13:34:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0b600c3-9c85-4264-91dd-056a605d4c6f</guid><dc:creator>Chongchun Moon</dc:creator><description>&lt;p&gt;It works!&lt;/p&gt;
&lt;p&gt;Thank&amp;nbsp; you very much.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Chongchun Moon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I like to convert private key to code.</title><link>https://devzone.nordicsemi.com/thread/185082?ContentTypeID=1</link><pubDate>Fri, 03 May 2019 08:18:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a624282-487d-4992-b33b-352fb728427d</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Moon,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m really sorry for the dragging of the case. We found the issue. When generating by nrfutil, the endianess needed to be swapped. But the&amp;nbsp;private key SK is only one entity when the public key are 2 entities.&amp;nbsp;&lt;br /&gt;So the private key need to be swapped once when the public key need to be double swapped:&lt;/p&gt;
&lt;p&gt;For SK:&amp;nbsp; nrf_crypto_internal_swap_endian(sk_copy, sk, sizeof(sk) );&lt;/p&gt;
&lt;p&gt;For PK:&amp;nbsp;&amp;nbsp; &amp;nbsp; nrf_crypto_internal_double_swap_endian(pk_copy, pk, sizeof(pk) / 2);&lt;/p&gt;
&lt;p&gt;I attached here the &lt;span&gt;ecdsa&amp;nbsp;&lt;/span&gt;example that I used the keys generated by nrfutil to test:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-05bdc2c4d4034db693d7e8d993e88ad9/main.c"&gt;devzone.nordicsemi.com/.../main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here is the hex keys from nrfutil:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " height="119" src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-05bdc2c4d4034db693d7e8d993e88ad9/a11.png" width="624" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I like to convert private key to code.</title><link>https://devzone.nordicsemi.com/thread/184913?ContentTypeID=1</link><pubDate>Thu, 02 May 2019 13:11:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4285bfbf-67e4-4564-a8a5-25e31a2e7c69</guid><dc:creator>Chongchun Moon</dc:creator><description>&lt;p&gt;Hi Hung Bui,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;Okay. Thanks for response.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;Chongchun Moon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I like to convert private key to code.</title><link>https://devzone.nordicsemi.com/thread/184876?ContentTypeID=1</link><pubDate>Thu, 02 May 2019 12:10:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:90c009e4-c864-42bf-8437-a45ffbba9d0c</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Moon,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m really sorry for the late response. I was out of office in the last 2 weeks. I tried to test what you wanted to do and had the same issue. I have contacted our team to find the reason why it didn&amp;#39;t work but haven&amp;#39;t got the solution yet.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I will try to push this. Will update you if I have any response from the team.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I like to convert private key to code.</title><link>https://devzone.nordicsemi.com/thread/183156?ContentTypeID=1</link><pubDate>Tue, 23 Apr 2019 13:55:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7666cb2-665b-42e3-a246-d0ef9867ef97</guid><dc:creator>Chongchun Moon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Is there any update for this?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Chongchun Moon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I like to convert private key to code.</title><link>https://devzone.nordicsemi.com/thread/181352?ContentTypeID=1</link><pubDate>Wed, 10 Apr 2019 13:58:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5631be57-c8ea-49d7-8d39-b5784586e1d3</guid><dc:creator>Chongchun Moon</dc:creator><description>&lt;p&gt;Thanks.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; I will wait for good news &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I like to convert private key to code.</title><link>https://devzone.nordicsemi.com/thread/181276?ContentTypeID=1</link><pubDate>Wed, 10 Apr 2019 10:10:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ba10517-1aa0-4eef-ba03-bd9f93b139af</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Moon,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Ok so you just want to try encrypt a message using the same private key and public key generated by nrfutil.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I will try to test here and let you now if it works.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I like to convert private key to code.</title><link>https://devzone.nordicsemi.com/thread/181160?ContentTypeID=1</link><pubDate>Tue, 09 Apr 2019 17:37:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a114119-1ebb-4bad-88d3-1e760b444727</guid><dc:creator>Chongchun Moon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;I just use example(examples\crypto\nrf_crypto\ecdsa) in the SDK&lt;/p&gt;
&lt;p&gt;&amp;nbsp;And, I just replaced private key and public key on that example as my previous comment.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;So, I believe I am using same hash and generation procedure for signature is no problem.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Anyway,&amp;nbsp; code is attached as below.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/** @brief Alice signs the message.
 */
static void alice_sign()
{
    static nrf_crypto_ecc_private_key_t alice_private_key;
    ret_code_t                          err_code = NRF_SUCCESS;

    NRF_LOG_INFO(&amp;quot;Alice&amp;#39;s signature generation&amp;quot;);

    // Alice converts her raw private key to internal representation
    err_code = nrf_crypto_ecc_private_key_from_raw(&amp;amp;g_nrf_crypto_ecc_secp256r1_curve_info,
                                                   &amp;amp;alice_private_key,
                                                   m_alice_raw_private_key,
                                                   sizeof(m_alice_raw_private_key));
    DEMO_ERROR_CHECK(err_code);

    // Alice generates signature using ECDSA and SHA-256
    m_signature_size = sizeof(m_signature);
    err_code = nrf_crypto_ecdsa_sign(NULL,
                                     &amp;amp;alice_private_key,
                                     m_hash,
                                     sizeof(m_hash),
                                     m_signature,
                                     &amp;amp;m_signature_size);
    DEMO_ERROR_CHECK(err_code);

    // Alice can now send the message and its signature to Bob
    print_hex(&amp;quot;Alice&amp;#39;s message hash: &amp;quot;, m_hash, sizeof(m_hash));
    print_hex(&amp;quot;Alice&amp;#39;s signature: &amp;quot;, m_signature, m_signature_size);

    // Key deallocation
    err_code = nrf_crypto_ecc_private_key_free(&amp;amp;alice_private_key);
    DEMO_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="2121" url="~/f/nordic-q-a/45804/i-like-to-convert-private-key-to-code/181111"]You can check if the signature you generate using the private key in your code match with the signature generated by nrfutil.&amp;nbsp;[/quote]
&lt;p&gt;How can I check the signature? Please help me out to do it.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Could you tell me private key conversion as below is correct?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&amp;nbsp; Private key generation :&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;nrfutil keys display --key sk --format hex .\test.pem&lt;/p&gt;
&lt;p&gt;&amp;nbsp;WARNING: Security risk! Do not share the private key.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Private (signing) key sk:&lt;br /&gt;&amp;nbsp;&lt;strong&gt;b954ae7fea6910692bd6879072074ea1519676922f11984290f2f24ddb104904&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&amp;nbsp;Private key conversion :&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;static uint8_t m_alice_raw_private_key[] =&lt;br /&gt;{&lt;br /&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; 0xb9, 0x54, 0xae, 0x7f, 0xea, 0x69, 0x10, 0x69, &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; 0x2b, 0xd6, 0x87, 0x90, 0x72, 0x07, 0x4e, 0xa1, &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; 0x51, 0x96, 0x76, 0x92, 0x2f, 0x11, 0x98, 0x42, &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp; 0x90, 0xf2, 0xf2, 0x4d, 0xdb, 0x10, 0x49, 0x04,&lt;/strong&gt;&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Chongchun Moon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I like to convert private key to code.</title><link>https://devzone.nordicsemi.com/thread/181111?ContentTypeID=1</link><pubDate>Tue, 09 Apr 2019 14:18:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b6f9419-7a2e-4f6a-ac46-495b8ab1694b</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Could you show how you generate the&amp;nbsp;signature from the private key ? Have you check if you have the same hash of the init package&amp;nbsp; ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can check if the signature you generate using the private key in your code match with the signature generated by nrfutil.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Be careful about the endianess of the signature. We send the signature in little-endian but when doing verify we need it in big-endian.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I like to convert private key to code.</title><link>https://devzone.nordicsemi.com/thread/180794?ContentTypeID=1</link><pubDate>Mon, 08 Apr 2019 13:47:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b114a521-5c52-4569-b391-0b5a6cd70330</guid><dc:creator>Chongchun Moon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Yes, That&amp;#39;s what I want to do it. But, I couldn&amp;#39;t make it.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;I generated Private key and public key as below.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/key_5F00_generation_5F00_pc.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I converted it manually. and replace those keys. I used ECDSA example in SDK.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static uint8_t m_alice_raw_private_key[] =
{
    //0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,  // This is an example. DO NOT USE THIS KEY!
    //0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,  // This is an example. DO NOT USE THIS KEY!
    //0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,  // This is an example. DO NOT USE THIS KEY!
    //0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,  // This is an example. DO NOT USE THIS KEY!
    0xb9, 0x54, 0xae, 0x7f, 0xea, 0x69, 0x10, 0x69, 
    0x2b, 0xd6, 0x87, 0x90, 0x72, 0x07, 0x4e, 0xa1, 
    0x51, 0x96, 0x76, 0x92, 0x2f, 0x11, 0x98, 0x42, 
    0x90, 0xf2, 0xf2, 0x4d, 0xdb, 0x10, 0x49, 0x04,
};

/** @brief Predefined example public key that is associated with example private key
 *  @ref m_alice_raw_private_key.
 */
static uint8_t m_alice_raw_public_key[] =
{
#if 0
    0x02, 0x17, 0xE6, 0x17, 0xF0, 0xB6, 0x44, 0x39,
    0x28, 0x27, 0x8F, 0x96, 0x99, 0x9E, 0x69, 0xA2,
    0x3A, 0x4F, 0x2C, 0x15, 0x2B, 0xDF, 0x6D, 0x6C,
    0xDF, 0x66, 0xE5, 0xB8, 0x02, 0x82, 0xD4, 0xED,
    0x19, 0x4A, 0x7D, 0xEB, 0xCB, 0x97, 0x71, 0x2D,
    0x2D, 0xDA, 0x3C, 0xA8, 0x5A, 0xA8, 0x76, 0x5A,
    0x56, 0xF4, 0x5F, 0xC7, 0x58, 0x59, 0x96, 0x52,
    0xF2, 0x89, 0x7C, 0x65, 0x30, 0x6E, 0x57, 0x94,
#endif
    0x63, 0xa3, 0x1f, 0xef, 0x96, 0x79, 0xb7, 0x80, 
    0x43, 0x49, 0x89, 0x99, 0xea, 0x7d, 0xe8, 0xd0, 
    0x78, 0x4e, 0x8b, 0x4f, 0x2d, 0xa4, 0xcd, 0xf8, 
    0x52, 0x74, 0x42, 0x5a, 0x2d, 0x5a, 0xc0, 0xce,
    0xd0, 0x28, 0x7a, 0xe1, 0xc1, 0x53, 0xd9, 0x9c, 
    0x44, 0x84, 0x14, 0x0c, 0x2d, 0xa6, 0x21, 0xd2, 
    0xe5, 0xea, 0x83, 0x1b, 0x3b, 0x6a, 0xa7, 0x61, 
    0xd1, 0xef, 0x56, 0x55, 0xa1, 0x33, 0xe9, 0xd3
};
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But, It fail to verify.&lt;/p&gt;
&lt;p&gt;Do I miss something?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I like to convert private key to code.</title><link>https://devzone.nordicsemi.com/thread/180670?ContentTypeID=1</link><pubDate>Mon, 08 Apr 2019 08:55:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b99017c-b639-4f88-9f00-63faa047beb7</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Moon,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So you want to convert this:&amp;nbsp;&lt;span&gt;6a72e923fa15c81782c90a02f6c7e9755d4509c5d9be16e5f9f2830fae7754dc to something like this:&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;__ALIGN(4) const uint8_t pk[64] =&lt;br /&gt;{&lt;br /&gt; 0x6a, 0x72, 0xe9, 0x23,....&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I think you can do it manually. If you want to automated it I would suggest to have a look into the&amp;nbsp;get_vk_code function &lt;a href="https://github.com/NordicSemiconductor/pc-nrfutil/blob/629475fb9d4c82d5b180186005c0c9eabf90408a/nordicsemi/dfu/signing.py#L231"&gt;here&lt;/a&gt;&amp;nbsp;and modify it so you can generate the private key in code format.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I like to convert private key to code.</title><link>https://devzone.nordicsemi.com/thread/180553?ContentTypeID=1</link><pubDate>Fri, 05 Apr 2019 15:54:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:521afdf0-aa24-4786-8fcb-a4dee584523c</guid><dc:creator>Chongchun Moon</dc:creator><description>&lt;p&gt;Sorry for confusion.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;I like to convert private key( which is generated by nrfutil) from *.pem to code style format to use in device.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;What I like to do is verifying authentication on both side PC and device using same private key and public key.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;Chongchun Moon&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I like to convert private key to code.</title><link>https://devzone.nordicsemi.com/thread/180547?ContentTypeID=1</link><pubDate>Fri, 05 Apr 2019 15:23:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca072474-8c61-491f-823d-59cd3a40c6f5</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Moon,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Could you clarify what exactly you want to have ?&amp;nbsp; what exactly is &amp;quot;to code&amp;quot;&amp;nbsp; that you want ?&lt;/p&gt;
&lt;p&gt;What do you plan to do on PC ?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>