I'm trying to implement an AES encryption function on my ESP8266 controller, using Arduino ide and this aes library. I finally made it work after many attempts but the output i get from the encryption function is only numerical and it doesn't correspond to other encryptions made by other softwares.
This is the code part relative to the AES encryption:
#include <AES.h>
AES aes ;
byte *key = (unsigned char*)"0123456789010123";
unsigned long long int my_iv = 36753562;
tempToken = RANDOM_REG32 % 10000;
randomstr = String(tempToken);
//answer = "{\"token\":\"" + randomstr + "\"}";
byte plain[4];
randomstr.getBytes(plain, 4);
Serial.println(randomstr);
Serial.println(plain[0]);
Serial.println(plain[1]);
Serial.println(plain[2]);
Serial.println(plain[3]);
byte cipher [48];
// aes.iv_inc();
byte iv [N_BLOCK] ;
aes.set_IV(my_iv);
aes.do_aes_encrypt(plain, 48, cipher, key, 128, iv);
String ciphertoken = "";
for (int i = 0; i < 48; i++) {
ciphertoken += cipher[i];
}
answer = "{\"token\":\"" + ciphertoken + "\"}";
It basically generates a random number between 0 - 9999, then converts it in a byte array (because aes function needs a byte array as input), then encrypt this byte array and prints the output, written in cipher
byte array.
This is the output I get from it
6188
54
49
56
0
{"token":"521111513725521540120674957151112223103194250224197251261938514437131212302201813929189123134524113912554682501508415421130220"}
I can't understand if I did something wrong of if it is formatted in a strange way and if I can get the right encryption from it