# AES-CTR decryption

**URL:** <https://discourse.nodered.org/t/aes-ctr-decryption/46509>\
**Category:** General\
**Created:** [31 May 2021 13:20 UTC](https://discourse.nodered.org/t/aes-ctr-decryption/46509 "2021-05-31T13:20:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DuncanCT](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/duncanct/32/41639_2.png) [@DuncanCT](https://discourse.nodered.org/u/DuncanCT)\
**Post date:** [31 May 2021 13:20 UTC](https://discourse.nodered.org/t/aes-ctr-decryption/46509/1 "2021-05-31T13:20:39Z")

</div>

I'm having problems decoding specific AES messages.

Used this site for testing... [AES Encryption: Encrypt and decrypt online — Cryptii](https://cryptii.com/pipes/aes-encryption) - result of encrypting (4d 65 73 73 61 67 65 = 4a 9b 9c 07 80 b2 66)

Setting:  
Algorithm: AES-128  
Mode: CTR  
Key: 000102030405060708090a0b0c0d0e0f  
IV: 101112131415161718191a1b1c1d1e1f

Key and IV from here... [CryptoJS - CryptoJS](https://cryptojs.gitbook.io/docs/)

Here is my code from Node-RED...

```auto
var cryptojs = context.global.cryptojs;

var key = '000102030405060708090a0b0c0d0e0f';
var iv = '101112131415161718191a1b1c1d1e1f';
var data = msg.payload;

var message = cryptojs.AES.decrypt(
    data, 
    key, { 
        mode: cryptojs.mode.CTR, 
        iv: iv }
    );

msg.payload = message.toString();

return msg;

```

Decrypting 4a 9b 9c 07 80 b2 66 return "" from a debug node.

I feel like the format (HEX) of the imput might be a problem.

Disclaimer: Noob. TIA

```auto
[{"id":"380fc06d.ed624","type":"inject","z":"70a6ffe1.f9ce8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"4a9b9c0780b266","payloadType":"str","x":160,"y":760,"wires":[["dfac1e54.967ca"]]},{"id":"3a32b386.be581c","type":"debug","z":"70a6ffe1.f9ce8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":550,"y":760,"wires":[]},{"id":"dfac1e54.967ca","type":"function","z":"70a6ffe1.f9ce8","name":"decrypt","func":"var cryptojs = context.global.cryptojs;\n\nvar key = '000102030405060708090a0b0c0d0e0f';\nvar iv = '101112131415161718191a1b1c1d1e1f';\nvar data = msg.payload;\n\nvar message = cryptojs.AES.decrypt(\n data, \n key, { \n mode: cryptojs.mode.CTR, \n iv: iv }\n );\n\nmsg.payload = message.toString();\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":760,"wires":[["3a32b386.be581c"]]}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 July 2021 13:21 UTC](https://discourse.nodered.org/t/aes-ctr-decryption/46509/2 "2021-07-30T13:21:37Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
