Array<char> *CloudComm::encryptSlotAndPrependIV(Array<char> *rawData, Array<char> *ivBytes) {
try {
Array<char> *encryptedBytes = AESEncrypt(ivBytes, key, rawData);
- Array<char> *origBytes = AESDecrypt(ivBytes, key, encryptedBytes);
- if (!rawData->equals(origBytes))
- throw new Error("BAD");
Array<char> *chars = new Array<char>(encryptedBytes->length() + CloudComm_IV_SIZE);
System_arraycopy(ivBytes, 0, chars, 0, ivBytes->length());
System_arraycopy(encryptedBytes, 0, chars, CloudComm_IV_SIZE, encryptedBytes->length());
-
+ delete encryptedBytes;
return chars;
} catch (Exception *e) {
throw new Error("Failed To Encrypt");
Array<char> *encryptedBytes = new Array<char>(rawData->length() - CloudComm_IV_SIZE);
System_arraycopy(rawData, 0, ivBytes, 0, CloudComm_IV_SIZE);
System_arraycopy(rawData, CloudComm_IV_SIZE, encryptedBytes, 0, encryptedBytes->length());
- return AESDecrypt(ivBytes, key, encryptedBytes);
+ Array<char> * data = AESDecrypt(ivBytes, key, encryptedBytes);
+ delete encryptedBytes;
+ delete ivBytes;
+ return data;
} catch (Exception *e) {
throw new Error("Failed To Decrypt");
}
int64_t sequencenumber = slot->getSequenceNumber();
Array<char> *slotBytes = slot->encode(mac);
Array<char> *chars = encryptSlotAndPrependIV(slotBytes, slot->getSlotCryptIV());
+ delete slotBytes;
IoTString *url = buildRequest(true, sequencenumber, max);
timer->startTime();
wc = openURL(url);
writeURLDataAndClose(&wc, chars);
+ delete chars;
timer->endTime();
} catch (ServerException *e) {
timer->endTime();
Array<char> *rawData = new Array<char>(sizesofslots->get(i));
readURLData(wc, rawData);
Array<char> *data = stripIVAndDecryptSlot(rawData);
+ delete rawData;
slots->set(i, Slot_decode(table, data, mac));
+ delete data;
}
return slots;
}