计算Blob的MD5哈希值

[英]Calculate the MD5 hash of Blob


How can I calculate the MD5 hash of a Blob and check against another hash to see if they have changed?

如何计算Blob的MD5哈希并检查另一个哈希以查看它们是否已更改?

EDIT: I'm currently using CryptoJS

编辑:我目前正在使用CryptoJS

1 个解决方案

#1


4  

You can use the FileReader API to get the contents of the blob for comparison. If you have to use CryptoJS for this, you can use readAsBinaryString:

您可以使用FileReader API获取blob的内容以进行比较。如果你必须使用CryptoJS,你可以使用readAsBinaryString:

var a = new FileReader();
a.readAsBinaryString(blob);
a.onloadend = function () {
  console.log(CryptoJS.MD5(CryptoJS.enc.Latin1.parse(a.result)));
};

Note that readAsBinaryString is deprecated, so if you can use another library, such as SparkMD5, you could use an array buffer instead:

请注意,不推荐使用readAsBinaryString,因此如果您可以使用其他库(如SparkMD5),则可以使用数组缓冲区:

var a = new FileReader();
a.readAsArrayBuffer(blob);
a.onloadend = function () {
  console.log(SparkMD5.ArrayBuffer.hash(a.result));
};
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2013/12/17/13d1b45a5a9269e6cf5eea45a859bac.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告