Qt之大檔案獲取MD5值

2021-08-13 21:18:00 字數 959 閱讀 4460

原創 2023年08月18日 17:18:04

在qt中,qcryptographichash類提供了生成密碼雜湊的方法。該類可以用於生成二進位制或文字資料的加密雜湊值。目前支援md4、md5、sha-1、sha-224、sha-256、sha-384和sha-512。

這個類在qtcore4.3中被引入。 

小檔案內容加密的時候,直接將檔案內容傳進入加密即可,但遇到大檔案的時候這樣的辦法需要優化。

思路就是:在迴圈中不停讀檔案,讀到一定大小的檔案內容,就拿去算md5值,這樣就保證了儲存檔案內容的變數不會溢位。

[cpp]

view plain

copy

#include 

#include 

#include 

#include 

#include 

qbytearray getfilemd5(qstring filepath)  

qcryptographichash ch(qcryptographichash::md5);  

quint64 totalbytes = 0;  

quint64 byteswritten = 0;  

quint64 bytestowrite = 0;  

quint64 loadsize = 1024 * 4;  

qbytearray buf;  

totalbytes = localfile.size();  

bytestowrite = totalbytes;  

while

(1)  

else

if(byteswritten == totalbytes)  

}  localfile.close();  

qbytearray md5 = ch.result();  

return

md5;  

}  

python獲取檔案MD5值

在比較兩個資料夾內的兩個壓縮包是否相同,可以採用判斷兩個壓縮包的md5是否相等。md5也是有可能會判斷失誤的,了解一下md5碰撞演算法 python獲取檔案md5 import os import hashlib def get md5 filename if not os.path.isfile ...

js獲取檔案MD5值

要在web頁面中計算檔案的md5值,還好這個專案是只需相容現代瀏覽器的,不然要坑死了。其實對檔案進行md5,對於後端來說是及其簡單的。比如使用node.js,只要下面幾行 就可以了 var fs require fs var crypto require crypto function md5fil...

python 實現大檔案md5值計算

python 中使用hashlib模組實現常見摘要演算法,如md5 sha1等。hashlib.md5 檔案內容 實現了對檔案的md5計算,注意引數為檔案內容而不是檔案路徑。import hashlib with open 2.jpeg rb as f data f.read d5 hashlib....