Using the HTML5 File API and any JavaScript crypto library, how can I generate an MD5 hash of the file?
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:
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With