4 * Compute the SHA256HMAC of a message on an ESP8266
7 /* The length of the key we will use for this HMAC */
8 /* The key can be of any length, 16 and 32 are common */
15 Serial.println("SHA256HMAC example");
18 byte key[KEY_LENGTH] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
20 /* Create the HMAC instance with our key */
21 SHA256HMAC hmac(key, KEY_LENGTH);
23 /* Update the HMAC with just a plain string (null terminated) */
24 hmac.doUpdate("Hello World");
26 /* And or with a string and length */
27 const char *goodbye = "GoodBye World";
28 hmac.doUpdate(goodbye, strlen(goodbye));
30 /* And or with a binary message */
31 byte message[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
32 hmac.doUpdate(message, sizeof(message));
34 /* Finish the HMAC calculation and return the authentication code */
35 byte authCode[SHA256HMAC_SIZE];
36 hmac.doFinal(authCode);
38 /* authCode now contains our 32 byte authentication code */
39 for (byte i=0; i < SHA256HMAC_SIZE; i++)
41 if (authCode[i]<0x10) { Serial.print('0'); }
42 Serial.print(authCode[i], HEX);