5

Well I tried hashing a string or at least a set of numbers in Python and compare it with the one generated using the MD5 Library updated by Scott MacVicar on the Arduino but the results I get are differents.

Arduino Code:

#include <MD5.h> void setup() { //initialize serial Serial.begin(9600); //give it a second delay(1000); //generate the MD5 hash for our string unsigned char* hash=MD5::make_hash("hello"); //generate the digest (hex encoding) of our hash char *md5str = MD5::make_digest(hash, 16); //print it on our serial monitor Serial.println(md5str); } 

Result: 5d41402abc4b2a76b9e4080020008c00

Python Code:

from hashlib import md5 m = md5('hello').hexdigest() print m 

Result: 5d41402abc4b2a76b9719d911017c592

From what I can see in every attempt is that the difference comes at the last 14 characters. But the length of the generated hashes are the same!

What am I doing wrong?? Thanks

Edit:

I used a command from the terminal and got:

echo -n 'hello' | openssl md5 

Result: 5d41402abc4b2a76b9719d911017c592

Which makes me think that the root of the problem is in the arduino code

4
  • Did you mean to echo 'hello'? I agree though, it's the Arduino that is wrong. Commented Oct 24, 2013 at 14:51
  • sorry edited lol yes but I wanted to know what's wrong with the code anyway Commented Oct 24, 2013 at 16:10
  • Did you ever resolve this or report this bug to the developer? Commented Mar 31, 2016 at 3:24
  • No, I gave up on the idea. I had other problems with other libraries as well but discussions are open for a solution Commented Mar 31, 2016 at 15:08

1 Answer 1

1

I'm going to assume that you are using the MD5 library from here: https://github.com/tzikis/ArduinoMD5/

It looks like that library has a bug. The MD5::make_hash() function returns a pointer to memory on the stack. Some of that memory must be being altered before the call to make_digest() so the resulting digest is partially wrong.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah I supposed that there was a bug on the library. Could it be that it's adding a "0" at the end?? I saw that problem a lot of times in forums

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.