ESP32-S3 V5.0.2 flash 手动生成密钥加密 _By星年(已验证)

环境 ESP32-S3 ESP_IDF V5.0.2 手动生成密钥加密

官方参考资料:
https://docs.espressif.com/projects/esp-idf/zh_CN/v5.0.2/esp32s3/search.html?q=generate_flash_encryption_key&check_keywords=yes&area=default

一、加密
(1)生成密钥

espsecure.py generate_flash_encryption_key my_flash_encryption_key.bin

(2)工程加密配置及串口配置安全模式

idf.py menuconfig

ESP32-S3 V5.0.2 flash 手动生成密钥加密 _By星年(已验证)_第1张图片ESP32-S3 V5.0.2 flash 手动生成密钥加密 _By星年(已验证)_第2张图片

(3)烧录密钥到设备(修改端口号)(只能烧录一次)

espefuse.py --port COM7 burn_key BLOCK_KEY1 my_flash_encryption_key.bin XTS_AES_128_KEY

(4)加密镜像并烧录(根据idf.py build编译后信息,修改文件路径、文件名、烧录地址及生成文件名)

idf.py build flash monitor
espsecure.py encrypt_flash_data --aes_xts --keyfile my_flash_encryption_key.bin --address 0x10000 --output esp32-bauer-ciphertext.bin build/esp32-bauer.bin
espsecure.py encrypt_flash_data --aes_xts --keyfile my_flash_encryption_key.bin --address 0x90000 --output ota_data_initial-ciphertext.bin build/ota_data_initial.bin

(5)烧录加密bin

esptool.py -p COM7 -b 460800 --before default_reset --after no_reset --chip esp32s3  write_flash --flash_mode dio --flash_size 16MB --flash_freq 80m 0x9000 ota_data_initial-ciphertext.bin 0x10000 esp32-bauer-ciphertext.bin

二、代码更新后烧录
编译

idf.py build

加密

espsecure.py encrypt_flash_data --aes_xts --keyfile my_flash_encryption_key.bin --address 0x10000 --output esp32-bauer-ciphertext.bin build/esp32-bauer.bin
espsecure.py encrypt_flash_data --aes_xts --keyfile my_flash_encryption_key.bin --address 0x90000 --output ota_data_initial-ciphertext.bin build/ota_data_initial.bin

烧录

esptool.py -p COM7 -b 460800 --before default_reset --after no_reset --chip esp32s3  write_flash --flash_mode dio --flash_size 16MB --flash_freq 80m 0x9000 ota_data_initial-ciphertext.bin 0x10000 esp32-bauer-ciphertext.bin --force

三、关闭加密和解密已加密镜像(关闭解密只有1次机会)

关闭加密

espefuse.py burn_efuse SPI_BOOT_CRYPT_CNT

常用命令:
1.查看是否加密:(修改端口号)

espefuse.py summary -p COM7

2.生成密钥:
(1)AES-128(256 位密钥)

espsecure.py generate_flash_encryption_key my_flash_encryption_key.bin

(2)AES-256(512 位密钥)

espsecure.py generate_flash_encryption_key --keylen 512 my_flash_encryption_key.bin

3.关闭加密:

espefuse.py --port COM7 burn_efuse SPI_BOOT_CRYPT_CNT

4.已加密代码烧录

idf.py encrypted-flash monitor

你可能感兴趣的:(物联网,网络,单片机,c语言,嵌入式硬件,ESP32)