NVS encryption
Posted: Tue Feb 21, 2023 1:34 pm
Hello
I can't find good documentation for NVS encryption using arduino framework online.
Using the ESP_IDF framework it should be not that hard. creating those bin's using the idf CLI worked, so that's not the problem, but the code...
If I understand correctly, the Preferences library is used as a wrapper for NVS, but that's not encrypted right? I found some code code snippets online that uses esp-idf framework:
But the nvs_specific methods (nvs_flash_read_security_cfg eg.) does not seem to work. They give me the error undefined reference to `nvs_flash_read_security_cfg'. It's not clear for me why it does that.
Any help would be nice!
I can't find good documentation for NVS encryption using arduino framework online.
Using the ESP_IDF framework it should be not that hard. creating those bin's using the idf CLI worked, so that's not the problem, but the code...
If I understand correctly, the Preferences library is used as a wrapper for NVS, but that's not encrypted right? I found some code code snippets online that uses esp-idf framework:
Code: Select all
// 1. find partition with nvs_keys
const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS_KEYS, "nvs_key");
if (partition == NULL)
{
log_e("Could not locate nvs_key partition. Aborting.");
return false;
}
// 2. read nvs_keys from key partition
nvs_sec_cfg_t cfg;
err = nvs_flash_read_security_cfg(partition, &cfg);
if (err != ESP_OK)
{
log_e("Failed to read nvs keys (rc=0x%x)", err);
return false;
}
// 3. initialize nvs partition
err = nvs_flash_secure_init(&cfg);
if (err != ESP_OK)
{
log_e("failed to initialize nvs partition (err=0x%x). Aborting.", err);
return false;
}
// 4. open nvs partition
err = nvs_open(name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle);
if (err != ESP_OK)
{
log_e("nvs_open failed: %s");
return false;
}
_started = true;
return true;
Any help would be nice!