Hi jremington, many thanks for your prompt response!
About my comment " ... without changing it from its value to its HEX equivalent ....", not making sense to you, please consider the following explanation to clear any misunderstandings, produced on my behalf. I am including - at the end - the sketch with the AES128 class where you may check the uint8_t variable needing to receive its content as a collection of bytes ....
EXPLANATION
(1) The following Cyphered TEXT -> 65D0F7758B094114AFA6D33A5EA0716A -> is received as a string in a remote located ARDUINO 33IoT device. However, the Cyphered TEXT originally is a uint8_t [16] variable, therefore the Cyphered TEXT sent as a string, originally is ->
0x65, 0xD0, 0xF7, 0x75, 0x8B, 0x09, 0x41, 0x14, 0xAF, 0xA6, 0xD3, 0x3A, 0x5E, 0xA0, 0x 71, 0x6A
i.e 16 bytes in Length, but sent as a string from a backend to a frontend device
(2) At the frontend side, the Cyphered TEXT is used as an input in the following class ->
AES128.runDec(key, 16, input, 16, dec_iv);
Where input is a uint8_t variable, within the class AES128 (BTW, there is not much backup info at github, available site for the class AES128)
(3) According to the latter, the original uint8_t 0x65, 0xD0, 0xF7, 0x75, 0x8B, 0x09, 0x41, 0x14, 0xAF, 0xA6, 0xD3, 0x3A, 0x5E, 0xA0, 0x 71, 0x6A, now “received” as a string “65D0F7758B094114AFA6D33A5EA0716A” - NEEDS TO BE CONVERTED back to its original format, i.e. uint8_t; otherwise, it will not fit into the AES128 class “input” variable, for it is defined as a uint8_t type.
(4) input variable needs to “receive” 16 bytes. When copying the string “65D0F7758B094114AFA6D33A5EA0716A”, which contains char – NOT Byte – to any other variable, each char “arrives” as a byte, therefore
“65D0F7758B094114AFA6D33A5EA0716A”
shall be
3635443046373735384230393431313441464136443333413545413037313641
REQUEST
What is finally needed is to pass each char of "65D0F7758B094114AFA6D33A5EA0716A" - as if it is a byte - into the "input" variable of class AES128, e.g. "65" string must arrive as 0x65, "D0" must arrive as 0xD0, and do on till final "6A" having to arrive as 0x6A
I am wrongly copying "65D0F7758B094114AFA6D33A5EA0716A", in such a way that it arrives into the "input" variable of the class AES128 as a BYTE, e.g. 6 arrives as 36; 5 arrives as 35 and so on, completing all original 32 chars in the string, but copied as 64 HEX char.
//Notes for decypher checking
//*********************************************************************************************
//AES128 Decryption of 'F8EC2769085E888FA68FC6309FA0451E' is 0x41726475696E6F41726475696E6F0000
//IV_Enc : 65D0F7758B094114AFA6D33A5EA0716A
//MENSAJE ENCRIPTADO : F8EC2769085E888FA68FC6309FA0451E
//*********************************************************************************************
//libraries needed to convert char variables into uint8_t
//-------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
//-------------------------------------------------------
#include <stdlib.h>
#include <ArduinoBearSSL.h>
#include "AES128.h"
// AES128 class declaration
//-------------------------------------------------------
#ifdef ARDUINO_ARCH_MEGAAVR
// Create the object
AES128Class AES128;
#endif
//-------------------------------------------------------
uint8_t key[16] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02};
uint8_t enc_iv[16] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01};
//uint8_t dec_iv[16] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01};
//uint8_t input[16] = "ArduinoArduino"; // {0x41,0x72,0x64,0x75,0x69,0x6E,0x6F,0x41,0x72,0x64,0x75,0x69,0x6E,0x6F,0x00,0x00}
uint8_t dec_iv[16] = {0x65,0xd0,0xf7,0x75,0x8b,0x09,0x41,0x14,0xaf,0xa6,0xd3,0x3a,0x5e,0xa0,0x71,0x6a};
//iv_dec => 65 D0 F7 75 8B 09 41 14 AF A6 D3 3A 5E A0 71 6A
uint8_t input[16] = {0xf8,0xec,0x27,0x69,0x08,0x5E,0x88,0x8f,0xa6,0x8f,0xc6,0x30,0x9f,0xa0,0x45,0x1e};
//input => F8 EC 27 69 08 5E 88 8F A6 8F C6 30 9F A0 45 1E
uint8_t inputRef[16] = {0x41,0x72,0x64,0x75,0x69,0x6E,0x6F,0x41,0x72,0x64,0x75,0x69,0x6E,0x6F,0x00,0x00};
uint8_t inputR[16];
uint8_t dec_ivR[16];
uint8_t arr[16]; // variable to cnevert String into char
char TestCharinput[3]; // Consider deleting
char charBuf[32];
char* charinput;
String EncryptedPost ="65D0F7758B094114AFA6D33A5EA0716AF8EC2769085E888FA68FC6309FA0451E";
//String EncryptedPost ="F8EC2769085E888FA68FC6309FA0451E663B3A72515695AE3748F8A7E08DC6C7";
//String EncryptedPost ="E89D5BE11DFC4295C9E13E2A250F4C85A1F1D8A79256DC6961E96B597DFA6867";
String PostRx="",PostRx_iv="",PostRx_input="";
String str,TestString = "",TestStringinput = "",TestStringoutputI="",TestStringoutput="";
String DECRYPTEDinput = " ";
String DECRYPTEDinputRef = " ";
boolean StatusVector[7]; // starts in 0 and ends in 5
boolean Flag;
void setup()
{
Serial.begin(9600);
while (!Serial);
//Status Vector initialisation
//----------------------------
StatusVector[0]=false;
StatusVector[1]=false;
StatusVector[2]=false;
StatusVector[3]=false;
StatusVector[4]=false;
StatusVector[5]=false;
StatusVector[6]=false;
//---------------------------
Serial.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
Serial.println("64 char length iV+Encrypted POST Decrypting Programme // Test1_AES128_SoloDecV2.1");
Serial.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
Serial.println(" ");
//Serial.println("------------------------------------------------------------------------------");
Serial.print("Message to decrypt => ");Serial.println(EncryptedPost);
Serial.println(" ");
Serial.println("-------------------------------------------------------------------------------------------------------------------------------------------");
}
void loop()
{
PostRx = EncryptedPost;
PostRx_iv = PostRx.substring(0,32);
PostRx_input = PostRx.substring(32,64);
Serial.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
Serial.print("PostRx_iv ... CHOPPED //");Serial.print(PostRx_iv);Serial.println("// ");
Serial.print("PostRx_input ... CHOPPED //");Serial.print(PostRx_input);Serial.println("// ");
Serial.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
//Converting a String into a byte array of Char in Hexa
//-----------------------------------------------------
//dataString.toCharArray(dataArray, dataString.length()); // <- EXAMPLE
PostRx_iv.toCharArray(charBuf, 33);
//TestStringinput="65D0F7758B094114AFA6D33A5EA0716A"; // only for test purposes
//TestStringinput="FooFooFooFooXxxXF"; // only for test purposes
//+++++++++++++++++++++++++++++++++++++++++++++
TestStringinput=PostRx_iv; // This variable cannot be larger than 16 Char. After char 16 it does not consider it!
//+++++++++++++++++++++++++++++++++++++++++++++
Serial.print("TestStringinput as String => ");Serial.print(TestStringinput);Serial.println("");
std::copy(TestStringinput.begin(),TestStringinput.end(), std::begin(arr));
char* input22 = (char *) arr;
TestStringoutputI = String(input22);
TestStringoutput = TestStringoutputI;
Serial.print("arr is TestStringinput as CHAR => ");printHex(arr,16);Serial.println("");
if(TestStringoutput.length()>16)
{
TestStringoutput = TestStringoutputI.substring(0,TestStringinput.length());
Serial.println("Warning TestStringintput is larger than 16 !");
}
Serial.print("TestStringoutput => ");Serial.print(input22);Serial.println("");
Serial.print("TestStringoutput back to original => ");Serial.print(TestStringoutput);Serial.println("");
TestStringoutput = "";
TestStringoutputI = "";
Serial.println("xxxxxxxxxxxxxxxxxxxxxxxx --- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
Serial.print("charBuf in in CHAR -----> ");Serial.println(charBuf);
Serial.print("PostRx_iv in STRING -----> ");Serial.println(PostRx_iv);
//-----------------------------------------------------
//Serial.println("------------------------------------------------------------------------------");
Serial.print("iV received & BEFORE Decryption //");
printHex(dec_iv, 16);
Serial.print("// for the Message //"); printHex(input, 16);Serial.print("// To be Decrypted ");
Serial.println(" ");
Serial.println(" ");
Serial.print("AES128 Decryption of //");
printHex(input, 16);
Serial.println("");
Serial.print("// is //0x");
AES128.runDec(key, 16, input, 16, dec_iv);
printHex(input, 16);
//Converting a byte array of Char - in HEX - into String
//---------------------------------------------------
char* input2 = (char *) input;
DECRYPTEDinput = String(input2); //Actual data
char* input3 = (char *) inputRef;
DECRYPTEDinputRef = String(input3); //Reference data to test the decrypting METHOD
//---------------------------------------------------
Serial.print("// for the original Message => //");Serial.print(DECRYPTEDinput);Serial.print("//");
Serial.println(" ");
Serial.println(" ");
Serial.print("IV_Dec after Decrypted: ");
printHex(dec_iv, 16);
Serial.println(" ");
Serial.print("Key: ");
printHex(key, 16);
Serial.println(" ");
if(DECRYPTEDinput == DECRYPTEDinputRef)
{
Serial.println("");
Serial.println("B I N G O => Decrypting process Complete & Successfull !");
Serial.println("");
}
DECRYPTEDinput ="";
DECRYPTEDinputRef ="";
// consider deleting when fully operational
//---------------------------------------------
StatusVector[0]=true;
StatusVector[1]=true;
StatusVector[2]=true;
StatusVector[3]=true;
StatusVector[4]=true;
StatusVector[5]=true;
StatusVector[6]=false;
//---------------------------------------------
Flag = StatusVector[0] && StatusVector[1] && StatusVector[2] && StatusVector[3] && StatusVector[4] && StatusVector[5] && StatusVector[6];
if(Flag){Serial.println("EXCELLENT HIT !");}
else {Serial.println("K U A K !");}
Serial.println("-------------------------------------------------------------------------------------------------------------------------------------------");
delay(2000);
while(1);
}
void printHex(uint8_t *text, size_t size) {
for (byte i = 0; i < size; i = i + 1) {
if (text[i] < 16) {
Serial.print("0");
}
Serial.print(text[i], HEX);
}
}