I am working with the Mbed TLS Library on an ESP32 board and a function i am using takes only unsigned char and also gives unsigned char as the output
mbedtls_aes_setkey_enc( &aes, key, 256 );
mbedtls_aes_crypt_cbc( &aes, MBEDTLS_AES_ENCRYPT, 48, iv, input, output );
I now need to display output using this method
Heltec.display->drawString(0, 0, String(output));
but here it only takes strings type... how do i go about converting the unsigned char to string here? or is there a better way to display the output (I am using a Heltec LoRa32 board with a 0.96-inch display)
here is the full code
#include "mbedtls/aes.h"
#include "heltec.h"
mbedtls_aes_context aes;
unsigned char key[32];
unsigned char iv[16];
unsigned char input [128];
unsigned char output[128];
size_t input_len = 40;
size_t output_len = 0;
void setup() {
Heltec.display->init();
Heltec.display->flipScreenVertically();
Heltec.display->setFont(ArialMT_Plain_10);
delay(1500);
Heltec.display->clear();
Heltec.display->drawString(0, 0, "Heltec.LoRa Initial success!");
Heltec.display->display();
delay(1000);
mbedtls_aes_setkey_enc( &aes, key, 256 );
mbedtls_aes_crypt_cbc( &aes, MBEDTLS_AES_ENCRYPT, 48, iv, input, output );
}
void loop() {
Heltec.display->clear();
Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);
Heltec.display->setFont(ArialMT_Plain_10);
Heltec.display->drawString(0, 0, String(output);
Heltec.display->display();
}
String((char*)output)? (assumingoutputis null terminated)outputis binary (encrypted) data, in which case displaying it as-is is not a good idea. You likely want to encode the raw bytes as a hex-encoded string first, then display that instead.