[英]Generate An MD5 Hash of An Image Using HTML5 / JavaScript
Using the HTML5 File API and any JavaScript crypto library, how can I generate an MD5 hash of the file? 使用HTML5 File API和任何JavaScript密码库,如何生成文件的MD5哈希?
To read the file: 读取文件:
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
// What goes here?
};
reader.readAsBinaryString(data.files[0]);
This goes there: 它去了那里:
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
// This goes here:
var hash = CryptoJS.MD5(CryptoJS.enc.Latin1.parse(contents));
};
Be sure you include the CryptoJS library: 确保包括CryptoJS库:
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.