使用HTML5 File API和任何JavaScript加密库,如何生成文件的MD5哈希?
要阅读文件:
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
// What goes here?
};
reader.readAsBinaryString(data.files[0]);
答案 0 :(得分:3)
这就是:
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));
};
确保包含CryptoJS库:
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script>