#include "Arduino.h"
#include "mbedtls/aes.h"
void setup() {
Serial.begin(115200);
//data= "Only 16character"
const char *hexString = "4933ad56f64319b32e027bce6338bd76";
unsigned char encrypted[16];
hexStringToByteArray(hexString, encrypted);
// Serial.println("Encrypted array:");
// Serial.print("{");
// for (int i = 0; i < 16; i++) {
// Serial.printf("0x%02x", encrypted[i]);
// if (i < 15) {
// Serial.print(", ");
// }
// }
// Serial.println("};");
char * key = "abcdefghijklmnop";
unsigned char decrypted[16];
mbedtls_aes_context aes;
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();
mbedtls_aes_free(&aes);
}
void loop() {}
void hexStringToByteArray(const char *hexString, unsigned char *byteArray) {
for (int i = 0; i < 16; i++) {
sscanf(hexString + 2 * i, "%2hhx", &byteArray[i]);
}
}