<?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>Decrypting secret hex output from AES CTR example in 3rd party application (python)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/86096/decrypting-secret-hex-output-from-aes-ctr-example-in-3rd-party-application-python</link><description>Here is the main.c file for AES CTR - /examples/crypto/nrf_crypto/aes/aes_ctr example project 
 &amp;#39;NORDIC SEMICONDUCTORAES&amp;amp;MAC TEST&amp;#39; is the key 
 Encrypted hex output: &amp;quot;12 DD C3 EE DF 6E 7E 04 C7 3B DD 0D A3 F5 8E 7E CF 6D A0 A6 76 60 8A 63 01 87 A5 F6</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 01 Apr 2022 10:23:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/86096/decrypting-secret-hex-output-from-aes-ctr-example-in-3rd-party-application-python" /><item><title>RE: Decrypting secret hex output from AES CTR example in 3rd party application (python)</title><link>https://devzone.nordicsemi.com/thread/361191?ContentTypeID=1</link><pubDate>Fri, 01 Apr 2022 10:23:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a84e45cf-0df5-4504-907b-cf4c41cab99a</guid><dc:creator>Prantae</dc:creator><description>&lt;p&gt;Thanks &lt;a href="https://devzone.nordicsemi.com/members/charlie-shao"&gt;Charlie&lt;/a&gt; I managed to resolve the problem with the key you hinted.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;for any this is my code.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="python"&gt;import binascii
import os
from Crypto.Cipher import AES
from Crypto.Util import Counter
def int_of_string(s):
    return int(binascii.hexlify(s), 16)
def encrypt_message(key, plaintext):
    iv = os.urandom(16)
    ctr = Counter.new(128, initial_value=int_of_string(iv))
    aes = AES.new(key, AES.MODE_CTR, counter=ctr)
    return iv + aes.encrypt(plaintext)
def decrypt_message(key, ciphertext):
    iv = ciphertext[:16]
    print(iv)
    ctr = Counter.new(128, initial_value=int_of_string(iv))
    aes = AES.new(key, AES.MODE_CTR, counter=ctr)
    return aes.decrypt(ciphertext[16:])

def nrf_hex_str_to_bytes(m_hex_str):
    split_nrf_plain_hex = x = m_hex_str.split(&amp;#39; &amp;#39;)
    split_nrf_plain_hex = &amp;quot;&amp;quot;.join(split_nrf_plain_hex)
    return bytes.fromhex(split_nrf_plain_hex)



if __name__ == &amp;#39;__main__&amp;#39;:
    #plain_key = &amp;#39;NORDIC SEMICONDUCTORAES&amp;amp;MAC TEST&amp;#39;
    plain_key = &amp;#39;NORDIC SEMICONDU&amp;#39;
    key = str.encode(plain_key)
    nrf_cipher = &amp;quot;12 DD C3 EE DF 6E 7E 04 C7 3B DD 0D A3 F5 8E 7E CF 6D A0 A6 76 60 8A 63 01 87 A5 F6 F6 26 B6 86 3A 07 B3 C0 FE D3 E5 3E 94 95 D5 05 EA 62 E7 23 4A F8 9A 20 4C 68 B2 2C D6 E5&amp;quot;
    nrf_cipher_iv = &amp;quot;00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 DD C3 EE DF 6E 7E 04 C7 3B DD 0D A3 F5 8E 7E CF 6D A0 A6 76 60 8A 63 01 87 A5 F6 F6 26 B6 86 3A 07 B3 C0 FE D3 E5 3E 94 95 D5 05 EA 62 E7 23 4A F8 9A 20 4C 68 B2 2C D6 E5&amp;quot;
    
    encrypted_byte = nrf_hex_str_to_bytes(nrf_cipher_iv)
    print(decrypt_message(key, encrypted_byte))&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Decrypting secret hex output from AES CTR example in 3rd party application (python)</title><link>https://devzone.nordicsemi.com/thread/360342?ContentTypeID=1</link><pubDate>Mon, 28 Mar 2022 14:05:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7d276dd8-f5d0-44f4-847f-5e7cc4e49405</guid><dc:creator>Charlie</dc:creator><description>&lt;p&gt;Hi Neel,&lt;/p&gt;
&lt;p&gt;I test on&amp;nbsp;&lt;a href="https://cryptii.com/pipes/aes-encryption"&gt;AES Encryption: Encrypt and decrypt online — Cryptii&lt;/a&gt;&amp;nbsp;seems everything works fine.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1648476181119v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Here AES-128 use on 128bit&amp;nbsp;key, so only &amp;quot;4E 4F 52 44 49 43 20 53 45 4D 49 43 4F 4E 44 55&amp;quot;(NORDIC SEMICONDU) is used.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Charlie&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Decrypting secret hex output from AES CTR example in 3rd party application (python)</title><link>https://devzone.nordicsemi.com/thread/359918?ContentTypeID=1</link><pubDate>Fri, 25 Mar 2022 07:24:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0eebb195-8880-408a-a944-412b40b1e8fe</guid><dc:creator>Prantae</dc:creator><description>&lt;p&gt;Does the encryption process have PKCS padding?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Decrypting secret hex output from AES CTR example in 3rd party application (python)</title><link>https://devzone.nordicsemi.com/thread/359908?ContentTypeID=1</link><pubDate>Fri, 25 Mar 2022 06:46:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6687d560-1428-4e40-9763-1752c73f7c7b</guid><dc:creator>Prantae</dc:creator><description>&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Decrypting secret hex output from AES CTR example in 3rd party application (python)</title><link>https://devzone.nordicsemi.com/thread/359785?ContentTypeID=1</link><pubDate>Thu, 24 Mar 2022 12:07:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bcccf582-2fce-42d4-b997-93165cb11b5f</guid><dc:creator>Charlie</dc:creator><description>&lt;p&gt;Hi Neel,&lt;/p&gt;
&lt;p&gt;I am checking the details with our development team and will feedback to you later.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Charlie&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>