Tenere i segreti fuori dal codice
Conservi le credenziali in sicurezza, non in testo semplice.
Tenere i segreti fuori dal codice è una lezione Arduino & IoT Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Arduino & IoT Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Arduino & IoT Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
What Counts as a Secret
WiFi passwords, API tokens, and private keys are all secrets. Anything that grants access must never sit in plain sight inside your sketch. 🔑
The Danger of Plaintext Keys
Flash memory can be read back over the wire. A plaintext key in your code is one chip dump away from being copied by anyone.
String apiKey = "AKIA12345SECRET"; // visible to anyone who reads the flashWhy Git Makes It Worse
Commit a secret once and it lives in your history forever. Even after you delete it, the old commit still holds the exposed key.
Use a Separate Header
Put credentials in a small file like secrets.h kept out of version control. This secrets header keeps keys off GitHub while your sketch stays shareable.
#include "secrets.h" // holds WIFI_SSID and WIFI_PASS, never committedIgnore It in Git
Add your secrets file to .gitignore so it can never be committed by accident. This single line prevents most real-world key leaks.
# .gitignore
secrets.hProvision at Setup Time
Instead of baking keys in, enter them once when the device first boots. Provisioning via a config page keeps secrets off your source entirely.
Store in NVS or EEPROM
The ESP32 offers NVS, a key-value store in flash for runtime secrets. You write the token once and read it back on every boot.
preferences.begin("net", false);
preferences.putString("token", userToken);One Device, One Key
Give each unit its own credentials, never a shared master key. With per-device keys, one stolen device can be revoked without touching the rest.
Rotate and Revoke
Plan to change keys on a schedule and kill leaked ones fast. Rotation limits how long any single stolen secret stays useful.
Least Privilege
Give each token only the access it truly needs. Least privilege means a leaked device key can read its own topic, not your whole account.
Scan Before You Push
Tools can catch a key before it reaches a remote repo. A secret scanner in your workflow blocks accidental leaks before they happen.
Quick Check
One of these keeps a key off your public repo.
Recap
Never bake secrets into code. Use a gitignored header, provision at setup, store in NVS, and keep per-device keys you can rotate. 🔐
Domande Frequenti
La lezione «Tenere i segreti fuori dal codice» è gratuita?
Sì — il testo completo di «Tenere i segreti fuori dal codice» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Arduino & IoT Academy, passa a CoddyKit PRO. Il corso Arduino & IoT Academy include 4 lezioni in totale.
Cosa imparerò in «Tenere i segreti fuori dal codice»?
Conservi le credenziali in sicurezza, non in testo semplice. Eserciti Arduino & IoT Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Arduino & IoT Academy?
Non è richiesta alcuna esperienza precedente. Arduino & IoT Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.
Quanto tempo richiede la lezione «Tenere i segreti fuori dal codice»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Arduino & IoT Academy?
Sì. Ogni lezione Arduino & IoT Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Superfici di attacco IoT comuni
- Tenere i segreti fuori dal codice
- Cifrare con TLS e verificare i certificati
- Firmare e proteggere il firmware