I'm using nlohmann/json library to represent sensitive information. Once the needed processing has been completed, I'm interested in securely erasing the keys of the json
type.
Example:
json test;
test["key1"] = "value1";
test["key2"] = "value2";
for (auto item = test.begin(); item != test.end(); ++item) {
// Processing going on here
// Let's print this information to simulate that it's "used"
// In the real application no data is printed / stored here,
// just processed.
std::cout << item.value().dump();
std::cout << item.key().dump();
// This particular key is not needed anymore here
}
// Keys are not needed here. How can I be sure
// that "key1" and "key2" are guaranteed
// not present in memory in any shape or form?
// Will this achieve my goal?
test.erase(test.begin(), test.end());
The result I'm trying to achieve is similar to what can be accomplished with the memset_s method or SecureZeroMemory on Microsoft platform.
Alternatively, a string contents can be replaced with some arbitrary information with the help of the std::fill algorithm:
std::fill(string.begin(), string.end(), 0);
My question is, would the proposed approach of calling erase
on the json
completely remove the keys from the memory, or is there a chance that contents of those strings still will be present in the memory?