Is it possible to ensure that keys (e.g. ssid, ssl certs) are wiped from the memory of a esp32?

I'm new to the esp32, coming from a IoT device security perspective.

Say a person was testing an esp32 application that utilized WIFI, in which sensitive keys are embedded in the firmware. They then overwrote the esp32 with a small led blink firmware in an attempt to clear said keys.

I would like to know if flashing a small "blink" program will be sufficient to remove the keys, so the esp32 could be repurposed without worry that a firmware dump would reveal past firmware information.

This question is specifically targeting scenarios where the esp32 is for development purposes (fuse bits are never burnt - mind I think there is a security flaw where chip can be dumped anyhow).

1 Answer 1


You can use esptool.py to run an erase_flash operation.

Erase Flash: erase_flash & erase_region

To erase the entire flash chip (all data replaced with 0xFF bytes):

esptool erase_flash

To erase a region of the flash, starting at address 0x20000 with length 0x4000 bytes (16KB):

esptool erase_region 0x20000 0x4000

The address and length must both be multiples of the SPI flash erase sector size. This is 0x1000 (4096) bytes for supported flash chips.

-- esptool basic commands

As far as copy protection goes you can encrypt the flash contents so even if the chip is read directly without the decryption key they won't be able to make any sense of the data.

  • Thanks for the information Majenko! I was wondering if in addition to your answer, if flashing blink firmware (or any other small custom firmware) will be sufficient in overwriting all existing firmware data? If true, then perhaps erase_flash will not be required.
    – PathToLife
    Commented May 2, 2022 at 2:16
  • @PathToLife I'm not sure if doing a normal code upload wipes all the flash or not. You could try doing a big upload followed by a small upload then read all the flash with esptool and see what remains of the big upload...
    – Majenko
    Commented May 2, 2022 at 8:27
  • Is there a way to create an application that, when replaced by someone inexperienced or malicious (that is, without the erase operation) will not leak data (easily)? I speak of data stored in the NVS or LittleFS or similar. I don't want to outright encrypt the entire device, though, since that has limitations and would break "free" software.
    – user47164
    Commented May 4, 2022 at 19:25
  • 1
    @RDragonrydr You could manually encrypt the data you store in the NVS using your own software in your sketch. Without the keys (which are in the sketch, so would be overwritten by new code) decrypting the data would be nigh on impossible.,
    – Majenko
    Commented May 4, 2022 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.