[英]Arduino & Python MD5
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. 好吧,我尝试在Python中散列一个字符串或至少一组数字,并将其与使用Scott MacVicar在Arduino上更新的MD5库生成的数字进行比较,但我得到的结果是不同的。
Arduino Code: Arduino代码:
#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 结果:5d41402abc4b2a76b9e4080020008c00
Python Code: Python代码:
from hashlib import md5
m = md5('hello').hexdigest()
print m
Result: 5d41402abc4b2a76b9719d911017c592 结果:5d41402abc4b2a76b9719d911017c592
From what I can see in every attempt is that the difference comes at the last 14 characters. 从我在每次尝试中看到的是,最后14个字符的区别。 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 结果:5d41402abc4b2a76b9719d911017c592
Which makes me think that the root of the problem is in the arduino code 这让我觉得问题的根源在于arduino代码
I'm going to assume that you are using the MD5 library from here: https://github.com/tzikis/ArduinoMD5/ 我将假设你从这里使用MD5库: https : //github.com/tzikis/ArduinoMD5/
It looks like that library has a bug. 看起来这个库有一个bug。 The
MD5::make_hash()
function returns a pointer to memory on the stack. MD5::make_hash()
函数返回指向堆栈内存的指针。 Some of that memory must be being altered before the call to make_digest()
so the resulting digest is partially wrong. 在调用
make_digest()
之前,必须更改某些内存,以便生成的摘要部分错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.