Skip to content

Not the same result while repeating the same operation #18

@Raphyyy

Description

@Raphyyy

Hi, thank you for your work :)

Environment : ESP8266 12E

I tested your librairy 3 times on the same string, but the results are not the same on each.

Here's my code :

#include <AES.h>
#include <Base64.h>

AES aes;

byte key[] = {0x4C, 0x7E, 0x19, 0x16, 0x28, 0x87, 0xD2, 0xA8, 0xAB, 0xF1, 0x15, 0x88, 0x02, 0xCF, 0x4E, 0x3C};
byte iv[] = {0x46, 0xc5, 0x12, 0x05, 0x3f, 0x1c, 0xc7, 0x1d, 0x2a, 0xa1, 0x27, 0xcd, 0xab, 0x7d, 0xcc, 0x9a};

char* message1 = "pmscnv687,232o,0";
char* message2 = "pmscnv687,232o,0";
char* message3 = "pmscnv687,232o,0";

void setup() {
  Serial.begin(115200);
  Serial.println("Booting...");  

  char encryptMsg1[200];
  encryptAES(message1, encryptMsg1);
  Serial.println(encryptMsg1);

  char encryptMsg2[200];
  encryptAES(message2, encryptMsg2);
  Serial.println(encryptMsg2);

  char encryptMsg3[200];
  encryptAES(message3, encryptMsg3);
  Serial.println(encryptMsg3);
}

void encryptAES(char* message, char* output)
{
  aes.set_key(key, sizeof(key));
  
  byte cipher[300];
  char b64data[300];

  memset(cipher, 0x00, 300);
  memset(b64data, '\0', 300);

  Serial.println("===");
  Serial.printf("%s , %d\n", message, strlen(message));

  //int b64len = base64_encode(b64data, message, strlen(message));
  // Encrypt! With AES128, our key and IV, CBC and pkcs7 padding    
  aes.do_aes_encrypt((byte*)message, strlen(message), cipher, key, 128, iv);
  base64_encode(output, (char*)cipher, aes.get_size());
}

Here the output :

===
pmscnv687,232o,0 , 16
rxUZg7tFONY5TjW8Kk6ehw==
===
pmscnv687,232o,0 , 16
hC/xnjNW7EiVgLM7u60bmw==
===
pmscnv687,232o,0 , 16
gm9YHW9WE8XPWRZEoJgTqg==

The first result is ok while decrypting, the 2 others are not.

I try to initialize the AES object in my encryptAES() function, I had the same result.

If I reset the sketch, I have exactly the same output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions