簡體   English   中英

Arduino和Python MD5

[英]Arduino & Python MD5

好吧,我嘗試在Python中散列一個字符串或至少一組數字,並將其與使用Scott MacVicar在Arduino上更新的MD5庫生成的數字進行比較,但我得到的結果是不同的。

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);
}

結果:5d41402abc4b2a76b9e4080020008c00

Python代碼:

from hashlib import md5

m = md5('hello').hexdigest()
print m    

結果:5d41402abc4b2a76b9719d911017c592

從我在每次嘗試中看到的是,最后14個字符的區別。 但生成的哈希的長度是一樣的!

我究竟做錯了什么?? 謝謝

編輯:

我使用終端的命令得到:

echo -n 'hello' | openssl md5

結果:5d41402abc4b2a76b9719d911017c592

這讓我覺得問題的根源在於arduino代碼

我將假設你從這里使用MD5庫: https//github.com/tzikis/ArduinoMD5/

看起來這個庫有一個bug。 MD5::make_hash()函數返回指向堆棧內存的指針。 在調用make_digest()之前,必須更改某些內存,以便生成的摘要部分錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM