|
1 | 1 | ---
|
2 |
| -title: 'Store your sensitive data safely when sharing a sketch' |
| 2 | +title: 'Store Sensitive Data in Sketches' |
3 | 3 | description: 'Learn how to share sketches without sharing the sensitive data such as Wi-Fi credentials and API keys.'
|
4 | 4 | ---
|
5 | 5 |
|
6 |
| -Often in your sketch, there is some sensitive data that you’d like to keep private, which could accidentally become public when published on GitHub or when you [share your sketch with someone else via URL](https://create.arduino.cc/projecthub/Arduino_Genuino/share-your-sketches-on-the-arduino-web-editor-00a02c). This sensitive information may include Wi-Fi network names and passwords, API key, and so on. But now, you can add a secret tab to your sketch and store your private data there. |
| 6 | +Often in your sketch, there is some sensitive data that you’d like to keep private, which could accidentally become public when published on GitHub or when you [share your sketch with someone else via URL]( |
| 7 | + |
7 | 8 |
|
8 |
| -This feature has been designed specifically for the [Arduino Create Editor](https://create.arduino.cc/editor). If you have yet to try it, follow [this tutorial to get started](https://create.arduino.cc/projecthub/Arduino_Genuino/getting-started-with-the-arduino-web-editor-4b3e4a) — all you need is an Arduino ID. |
9 | 9 |
|
10 |
| -## How it works |
11 |
| - |
12 |
| -Basically every time you type `SECRET_SOMETHING` in your sketch and save it, we will create a Secret tab for you to fill out. |
13 |
| - |
14 |
| -Let’s start with an example, just so you can see how it works. |
15 |
| - |
16 |
| -Go to the **Libraries panel** and type **‘Wifi101’** in the search tab, then click on the **ConnectWithWPA** example. You can also click on [this link](https://create.arduino.cc/editor/Arduino_Genuino/2ab7cb05-7f86-41cb-994f-d121d6f3bf34/preview) and add the example to your sketchbook. |
| 10 | +). This sensitive information may include Wi-Fi network names and passwords, API key, and so on. But now, you can add a secret tab to your sketch and store your private data there. |
17 | 11 |
|
18 |
| - |
| 12 | +This feature has been designed specifically for the [Arduino Cloud Editor](https://app.arduino.cc). If you have yet to try it, follow [Getting Started with Arduino Cloud](https://docs.arduino.cc/arduino-cloud/guides/overview/) — all you need is an Arduino ID. |
19 | 13 |
|
20 |
| -As you can see, there are some identifiers like `SECRET_SIID` and `SECRET_PSW`. If you now click on the tab called “Secret,” you will notice some input fields where you can fill in your data. |
21 |
| - |
22 |
| -If you have a [MKR1000](/hardware/mkr-1000-wifi) lying around, you can upload this sketch on it and watch your board connect to Internet (just make sure you join a 2GHz WiFi network). |
| 14 | +## How it works |
23 | 15 |
|
24 |
| - |
25 |
| - |
| 16 | +Basically every time you type `SECRET_SOMETHING` in your sketch and save it, we will create a Secret tab for you to fill out. |
26 | 17 |
|
27 | 18 | ## How to Add Secret Values to Your Own Sketch
|
28 | 19 |
|
29 |
| -Write your sketch as you would normally. |
| 20 | +Write your sketch as you would normally. Then click on the plus icon next to your sketch name and click on "Add Secrets Tab". |
30 | 21 |
|
31 |
| - |
| 22 | + |
32 | 23 |
|
33 |
| -In your sketch, replace the strings containing sensitive data by writing `SECRET_NAMEYOUWANT`. For instance, if your string is `"psw”`, you should replace it with `SECRET_PSW`. **Make sure all these identifiers are in caps.** |
| 24 | +In your sketch, replace the strings containing sensitive data by writing `SECRET_NAMEYOUWANT`. For instance, if your string is `"ssid`, you should replace it with `SECRET_SSID`. **Make sure all these identifiers are in caps.** |
34 | 25 |
|
35 |
| - |
| 26 | + |
36 | 27 |
|
37 |
| -The Secret tab will be automatically created **as soon as you type** `SECRET_SOMETHING`. Go to Secret tab and fill out the fields with the sensitive values. |
| 28 | +A new page will appear where you can enter your SECRET-Keys |
38 | 29 |
|
39 |
| - |
| 30 | + |
40 | 31 |
|
41 | 32 | That's it! If you share this sketch with someone via URL or if you download it, the values on the tab will be blank.
|
42 | 33 |
|
43 |
| - |
44 |
| - |
45 |
| -Alternatively, you can also click on the tab button and add the Secret tab directly from there. These instructions will be reported for quick reference. |
46 |
| - |
47 |
| - |
48 |
| - |
49 |
| - |
50 | 34 | ## Adding an extra optional field
|
51 | 35 |
|
52 |
| -If you want to add another field, let's say to store the pin for your SIM card, or an API token, we can add an optional field. All we need to do is adding this at the top of our sketch: |
53 |
| - |
54 |
| -```arduino |
55 |
| -const char optional[] = SECRET_OPTIONAL; |
56 |
| -``` |
57 |
| - |
58 |
| -So let's say we use `SECRET_SSID` and `SECRET_PASS`, this one would just be added in the same fashion. |
| 36 | +If you look at the examples above you notice we've also added a `SECRET_OPTIONAL_PASS`. This is used to store optional information e.g. a password that might be needed to connect to the Wi-Fi®. |
59 | 37 |
|
60 |
| - |
61 |
| - |
62 |
| -Now if we head over to the **Secret** tab, it will be visible, and you can input your optional credential. |
63 |
| - |
64 |
| - |
| 38 | +You can add it in the same fashion as the `SECRET_SSID` and add the `OPTIONAL` to it. |
65 | 39 |
|
66 | 40 | ## Download the sketch
|
67 | 41 |
|
68 | 42 | If you download a sketch, we will automatically create a file called arduino_secrets.h and add it to the .zip file. If you open the sketch with the Desktop IDE, you will be able to fill up this tab with your secrets as usual.
|
69 | 43 |
|
70 |
| - |
71 |
| - |
72 |
| - |
73 | 44 | ## Tech Details
|
74 | 45 |
|
75 | 46 | All the values you enter will be considered strings.
|
|
0 commit comments