#include "mbedtls/aes.h"
void setup() {
Serial.begin(115200);
mbedtls_aes_context aes;
char * key = "abcdefghijklmnop";
unsigned char encrypted[] = {0x56, 0x7a, 0x3b, 0x23, 0xb6, 0x83, 0xd8, 0x48, 0x8d, 0x5d, 0x40, 0xd2, 0xa5, 0x6e, 0x31, 0xd2};
unsigned char decrypted[16];
mbedtls_aes_init( &aes );
mbedtls_aes_setkey_dec( &aes, (const unsigned char*) key, strlen(key) * 8 ); // Set decryption key
// Decrypt the first block
mbedtls_aes_crypt_ecb(&aes, MBEDTLS_AES_DECRYPT, encrypted, decrypted);
Serial.println("Decrypted block 1:");
for (int i = 0; i < 16; i++) {
Serial.print((char)decrypted[i]);
}
Serial.println();
// Decrypt the second block
mbedtls_aes_crypt_ecb(&aes, MBEDTLS_AES_DECRYPT, encrypted + 16, decrypted);
Serial.println("Decrypted block 2:");
for (int i = 0; i < 16; i++) {
Serial.print((char)decrypted[i]);
}
Serial.println();
mbedtls_aes_free( &aes );
}
void loop() {}