0

我加密了我的 ssid 和密码(硬编码)。当我通过esptool.py read_flash命令读取整个闪存时,我可以在闪存文件中找到明文形式的凭据。我想保护我的 wifi ssid 和密码。是否有禁用此存储的命令?可以禁用nvs吗?这是我的代码:

#include <WiFi.h>
#include "mbedtls/aes.h"

char ssid[17], pass[17];

const char key[17] = "1234567890abcdef";

void Wifi_connected(WiFiEvent_t event, WiFiEventInfo_t info)
{
    Serial.println("Connected to AP!");
}

void Get_IPAddress(WiFiEvent_t event, WiFiEventInfo_t info)
{
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
}

void Wifi_disconnected(WiFiEvent_t event, WiFiEventInfo_t info)
{
    Serial.println("Trying to Reconnect...");
    WiFi.begin(ssid, pass);
}

void aes_decrypt(char *chipherText, char *key, char *outputBuffer)
{
    mbedtls_aes_context aes;
    mbedtls_aes_init(&aes);
    mbedtls_aes_setkey_dec(&aes, (const unsigned char *)key, strlen(key) * 8);
    mbedtls_aes_crypt_ecb(&aes, MBEDTLS_AES_DECRYPT, (const unsigned char *)chipherText, (unsigned char *)outputBuffer);
    mbedtls_aes_free(&aes);
}

void printArray(char *arr, int len)
{
    for (int i = 0; i < len; i++)
        Serial.print((char)arr[i]);
    Serial.println();
}

void setup()
{
    Serial.begin(115200);
    Serial.println("\nApp starts");

    char enc_ssid[33] = {0xEE, 0xBC, 0xEA, 0x5D, 0xD1, 0x74, 0xF9, 0x00, 0x8C, 0xCD, 0x83, 0xB5, 0xBA, 0xAB, 0xBC, 0x7D};
    char enc_pass[33] = {0x49, 0x5B, 0x89, 0xFB, 0xE0, 0x8C, 0xE8, 0x6A, 0xC8, 0xFE, 0x40, 0x30, 0x06, 0x68, 0x6B, 0x56};

    aes_decrypt(enc_ssid, (char *)key, ssid);
    aes_decrypt(enc_pass, (char *)key, pass);

    Serial.print("ssid: ");
    printArray(ssid, strlen(ssid));
    Serial.print("pass: ");
    printArray(pass, strlen(pass));

    WiFi.disconnect(true);
    delay(100);
    WiFi.onEvent(Wifi_connected, SYSTEM_EVENT_STA_CONNECTED);
    WiFi.onEvent(Get_IPAddress, SYSTEM_EVENT_STA_GOT_IP);
    WiFi.onEvent(Wifi_disconnected, SYSTEM_EVENT_STA_DISCONNECTED);

    WiFi.begin(ssid, pass);
    Serial.println("Wait for WiFi...");
}

void loop()
{
    delay(1000);
}
4

1 回答 1

0

问题已解决:

打电话

WiFi.persistent(false);

打电话之前

WiFi.begin();
于 2021-08-08T17:08:22.787 回答