Thank you @bko
So here is a boiled down look. I really cant post everything because it is pretty big.
Call from Application class:
String serverResponse = aesClient.cbcDecrypt(response.body, response.responseLength);
Method in aesClient class:
String aes_client::cbcDecrypt(String message, size_t len){
//Base 64 Decode data
const char *messageChars = message.c_str();
int length = len/4 *3;
if (messageChars[length - 1] == '=') (length)--;
if (messageChars[length - 2] == '=') (length)--;
unsigned char messageBuf[length];
size_t* decodeLength;
base64_decode(message.c_str(), message.length(), decodeLength, messageBuf);
//Copy Base 64 decoded data into buffer for decryption
unsigned char data[length];
memset(data, 0, sizeof data);
memcpy(data, messageBuf, length);
//get round key for decryption
memcpy(oIV, nIV, 16);
//Create output buffer for decryption.
unsigned char oBuf[length];
//Make sure buffers are empty
memset(oBuf, 0, length);
// Serial.print("Decrypt IV oIV: ");
// hexPrint(oIV, 16);
//
// Serial.print("Decrypt IV nIV: ");
// hexPrint(nIV, 16);
//Decrypt message into output buffer
aes_setkey_dec(&mAES, mKey, 128);
aes_crypt_cbc(&mAES, AES_DECRYPT, length, oIV, data, oBuf);
//Store first 16 decrypted characters as round key for next cbc encrypted send
memcpy(nIV, oBuf, 16);
if(validatePacket(oBuf)){
//Get checkin interval from packet
checkInInterval = ((oBuf[devIDLen+16] *256)+oBuf[devIDLen+17])*1000;
//Get message out of packet
char messageArray[(sizeof oBuf - (devIDLen+18))+1];
//Make sure messageArray is empty
memset(messageArray, 0, sizeof messageArray);
for(int i = 0; i < sizeof messageArray; i++){
messageArray[i] = oBuf[i+18+devIDLen];
}
String message(messageArray);
//Extrapolate message from received data. All messages are appended with ~ so trim off information past that symbol
int end = message.indexOf("~");
String trimmed = message.substring(0,end);
Serial.print("Length of return String after Decrypt: ");
Serial.println(trimmed.length());
delay(100);
return trimmed;
}else{
//Get message out of packet
char messageArray[(sizeof oBuf - (devIDLen+18))+1];
//Make sure messageArray is empty
memset(messageArray, 0, sizeof messageArray);
for(int i = 0; i < sizeof messageArray; i++){
messageArray[i] = oBuf[i+18+devIDLen];
}
String message(messageArray);
//Extrapolate message from received data. All messages are appended with ~ so trim off information past that symbol
int end = message.indexOf("~");
String trimmed = message.substring(0,end);
Serial.println(trimmed);
return "Fail";
}
}
Note that Length of return string after Decrypt print runs just before return in method so it does not break until the String is passed back to the Application class. If you need more information please let me know, I will be happy to post.