HASH 01: MD5 | Libelium
This example shows how to calculate MD5 message digest to provide INTEGRITY to the sending of information. Both data must be sent over the network: MESSAGE + HASH_MESSAGE

Required Materials

1 x Waspmote 1 x Battery

Notes

- The battery has to be connected. - This example can be executed in Waspmote v12 and Waspmote v15

Code

1
/*
2
* ------Waspmote HASH_01 MD5 Message Digest--------
3
*
4
* This example shows how to calculate MD5 message digest to
5
* provide INTEGRITY to the sending of information. Both data
6
* must be sent over the network: MESSAGE + HASH_MESSAGE
7
*
8
*
9
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
10
* http://www.libelium.com
11
*
12
* This program is free software: you can redistribute it and/or modify
13
* it under the terms of the GNU General Public License as published by
14
* the Free Software Foundation, either version 2 of the License, or
15
* (at your option) any later version.
16
*
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
21
*
22
* You should have received a copy of the GNU General Public License
23
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
*
25
* Version: 3.0
26
* Design: David Gascón
27
* Implementation: Alvaro Gonzalez, Yuri Carmona
28
*/
29
30
#include "WaspHash.h"
31
32
// Original message
33
char message[] = "Libelium";
34
35
// Variable to store the hash message
36
uint8_t hash_message_md5[16];
37
38
39
void setup()
40
{
41
USB.ON();
42
USB.println(F("HASH_01 example"));
43
USB.println();
44
}
45
46
47
void loop()
48
{
49
50
USB.print(F("Original message: "));
51
USB.println(message);
52
53
// Calculate hash of original message with MD5 Algorithm
54
HASH.md5( hash_message_md5, (uint8_t*)message, strlen(message)*8);
55
56
// Printing message digest MD5
57
USB.println(F("The message digest created for the original message is: "));
58
HASH.printMessageDigest("MD5:", hash_message_md5 , 16);
59
60
delay(5000);
61
USB.println();
62
USB.println(F("*******************"));
63
}
Copied!

Output

1
H#
2
HASH_01 example
3
4
Original message: Libelium
5
The message digest created for the original message is:
6
MD5:"D1954FB5A0452809755D28EA75AC6E85"
Copied!
Last modified 1yr ago