kakopappa / arduino-esp8266-aes-encryption-with-nodejs Goto Github PK
View Code? Open in Web Editor NEWHow to encrypt a string using AES in ESP 8226 and decrypt it in NodeJS
How to encrypt a string using AES in ESP 8226 and decrypt it in NodeJS
Hello,
Thank you for putting together this library.
I've installed it and the code fails to compile with an error:
AESLib.cpp:63:48: error: 'base64_encode' was not declared in this scope
Adding the following include to AESLib.cpp resolved the issue, the example code now compiles and runs as expected:
#include "Base64.h"
Adding that include to my sketch did not work.
I just tried your gift for an ESP32...
With your example I get:
11:50:38.671 -> Booting...
11:50:38.671 -> Let's encrypt:
11:50:38.671 -> IV b64: AAAAAAAAAAAAAAAAAAAAAA==
11:50:38.671 -> Message: {"data":{"value":300}, "SEQN":700 , "msg":"IT WORKS!!" }
11:50:38.671 -> Message in B64: eyJkYXRhIjp7InZhbHVlIjozMDB9LCAiU0VRTiI6NzAwICwgIm1zZyI6IklUIFdPUktTISEiIH0=
11:50:38.671 -> The lenght is: 76
11:50:38.671 -> Encryption done!
11:50:38.706 -> Cipher size: 80
11:50:38.706 -> Encrypted data in base64: 7bzIAnZUizSXRjIPTPysu9GXfiJohP8Ku2I9EUrviheRX9A+ecvsQaNvFveKtKGnTeAzOeCrK0WldZy8psT8NfLOsIjAXySlTjljf8PGAng=
11:50:38.706 -> Done...
Whatever key I use I always get:
IV b64: AAAAAAAAAAAAAAAAAAAAAA==
Hi kakopappa! Thanks for your awesome aes-encryption library.
I needed to decrypt in PHP and wrote a small port - see https://zeitwesentech.com/blog/?p=521
If you want you can also add that to your readme or provide a link to my post!
@kakopappa
Hi, I want to send string message about 7000-8000 length. I do not send with this code. How can I convert this code to send long message ?
AES.cpp应该改成:
void AES::calc_size_n_pad(int p_size){
int s_of_p = p_size;
if ( s_of_p % N_BLOCK == 0){
size = s_of_p + 16;
}else{
size = s_of_p + (N_BLOCK-(s_of_p % N_BLOCK));
}
pad = size - s_of_p;
}
AES.h应该改成:
byte arr_pad[16] = { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10 };/**< holds the hexadecimal padding values */
Hello i am trying to decode a message but i get unwanted chacters on the end of my message
the message has been created by nodejs , this is good library i rather use it .
this is my code , its very simple :
#include "AES.h"
#include "base64.h"
#include "ArduinoJson.h"
AES aes;
void setup() {
Serial.begin(115200);
Serial.println("\nBooting...");
byte IV[N_BLOCK] = {0x28 , 0xc1 , 0x58 , 0xc3 , 0x0b , 0x35 , 0x16 , 0xd7 , 0x8a , 0xd0 , 0xfc , 0x61 , 0xc5 , 0x03 , 0x23 , 0x2e};
byte KEY[] = {0xa6 , 0xf7 , 0xf8 , 0x72 , 0xc1 , 0x8e , 0x0b , 0xe2 , 0x0a , 0x77 , 0xa1 , 0x0e , 0xc5 , 0xe3 , 0x15 , 0x68};
byte DATA[] = {0x23 , 0x13 , 0x4c , 0xda , 0xa1 , 0xf4 , 0x4d , 0xcf , 0x5d , 0xfb , 0x85 , 0x55 , 0x1a , 0x63 , 0x78 , 0xdc , 0x9b , 0x22 , 0x7a , 0xb3 , 0x11 , 0x57 , 0x25 , 0xd6 , 0xe1 , 0xb0 , 0xf6 , 0x6f , 0x1b , 0xcb , 0xa2 , 0x0d , 0x43 , 0x7f , 0x08 , 0x2f , 0x5f , 0xb4 , 0xf1 , 0xa5 , 0xec , 0xd2 , 0x5a , 0x8f , 0xee , 0x9d , 0x64 , 0x37};
byte text[100]={0};
char text2[100]={0};
aes.do_aes_decrypt(DATA, sizeof(DATA) , text, KEY, 128, IV);
Serial.println();
for(int i=0;text[i];i++)
{
Serial.print((char)text[i]);
text2[i]=(char)text[i];
}
Serial.println();
String msge = String(text2);
msge.trim();
Serial.println(msge);
Serial.println("Done...");
}
void loop() {
// put your main code here, to run repeatedly:
}
this is the out put :
EXM1 : you should see number one end of line 1��
that two squares are more than what i need , i cant trim them , any idea why is this happening ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.