HELP! AES-128 Arduino

#include <AESLib.h>

AESLib aesLib;

void setup() {
    Serial.begin(115200);
    Serial.println("\nBooting...");  
  
  byte key[] = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C };
    
  // put your setup code here, to run once:
  byte my_iv[N_BLOCK] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  aesLib.gen_iv(my_iv);

  Serial.println("AES Key: ");
  int i;
  for (i = 0; i < sizeof(my_iv); i++)
  {
     Serial.print(my_iv[i], DEC); 
     Serial.print(",");
  }

  Serial.println("");

  String msg = "i like dogs";
  
  unsigned long ms = micros ();
  String encMsg = aesLib.encrypt(msg, key, my_iv);
  Serial.print("Encryption took: ");
  Serial.println(micros() - ms);  
  Serial.println("encMsg: " + encMsg);  

  String  sc = aesLib.decrypt(encMsg, key, my_iv);
  Serial.println(sc);
}

void loop() {
  // put your main code here, to run repeatedly:
  
}

Hi,

I use these codes with Arduino Nano. What is the solution that encryption works but does not work as the encryption is in the image below?

Regards

Share link of your AES Arduino IDE Library which you are using.

jackthom41: Share link of your AES Arduino Library which you are using.

https://github.com/kakopappa/arduino-esp8266-aes-lib

jackthom41

Regars

The code in that repository has the decrypt method commented out completely in AESLib.cpp.

I suspect only the lower level AES.h/AES.cpp is fully working?

you need to print it in HEX format .
try this :

Serial.print("encrypted data: ");

for (int i= 0; i<sizeof(my_iv); i++) { //printing in HEX format otherwise you get unreadable chars
Serial.print(my_iv*&0xFF, HEX);*

  • }*
  • Serial.println();*
    enjoy