How to encrypt a string using AES in ESP 8226 and decrypt it in NodeJS
Switch branches/tags
Nothing to show
Clone or download
Latest commit 843da7b Feb 11, 2017
Failed to load latest commit information.
AES.cpp first commit Feb 11, 2017
AES.h first commit Feb 11, 2017
AES_config.h first commit Feb 11, 2017
Base64.cpp first commit Feb 11, 2017
Base64.h first commit Feb 11, 2017 Update Feb 11, 2017
aes_encryption.ino first commit Feb 11, 2017
iv-5-snap.png console image file added Feb 11, 2017

"# arduino-esp8266-aes-encryption-with-nodejs"

This repo demostrates how to encypt your data using AES and decrypt it using NodeJS crypto-js library.

You can find the library version here

Complete article is here: (I am not the author)

I have fixed few bugs related ESP8266 and combined it with AES and Base64

How to use this:

  1. Clone the github repo.
  2. open aes_encryption.ino in Arduino
  3. Flash

conole output

  1. Copy the iv, encrypted data and replace the esp8266_msg, esp8266_iv in the javascript code below.

Here is the NodeJS Code.

//npm install --save-dev crypto-js
var CryptoJS = require("crypto-js");
var esp8266_msg = 'IqszviDrXw5juapvVrQ2Eh/H3TqBsPkSOYY25hOQzJck+ZWIg2QsgBqYQv6lWHcdOclvVLOSOouk3PmGfIXv//cURM8UBJkKF83fPawwuxg=';
var esp8266_iv  = 'Cqkbb7OxPGoXhk70DjGYjw==';

// The AES encryption/decryption key to be used.
var AESKey = '2B7E151628AED2A6ABF7158809CF4F3C';

var plain_iv =  new Buffer( esp8266_iv , 'base64').toString('hex');
var iv = CryptoJS.enc.Hex.parse( plain_iv );
var key= CryptoJS.enc.Hex.parse( AESKey );

console.log("Let's ");

// Decrypt
var bytes  = CryptoJS.AES.decrypt( esp8266_msg, key , { iv: iv} );
var plaintext = bytes.toString(CryptoJS.enc.Base64);
var decoded_b64msg =  new Buffer(plaintext , 'base64').toString('ascii');
var decoded_msg =     new Buffer( decoded_b64msg , 'base64').toString('ascii');

console.log("Decryptedage: ", decoded_msg);