我正在使用nlohmann/json库来表示敏感信息。完成所需的处理后,我有兴趣安全地擦除该类型的密钥json
。
例子:
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());
我试图实现的结果类似于使用memset_s方法或Microsoft 平台上的SecureZeroMemory可以实现的结果。
或者,可以借助std::fill算法将字符串内容替换为一些任意信息:
std::fill(string.begin(), string.end(), 0);
我的问题是,调用从内存中完全删除键的提议方法是否会出现,或者这些字符串的内容是否仍有可能存在于内存中?erase
json