Skip to content

Instantly share code, notes, and snippets.

@takatoh
Created August 12, 2018 01:43
Show Gist options
  • Save takatoh/5a585095489b110d9ca186ae301f9134 to your computer and use it in GitHub Desktop.
Save takatoh/5a585095489b110d9ca186ae301f9134 to your computer and use it in GitHub Desktop.
MD5 calculator
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>MD5 calculator</title>
<script type="text/javascript" src="js/md5.js"></script>
<script type="text/javascript">
function handleFileSelect(evt) {
let files = evt.target.files;
let output = document.getElementById("list");
output.innerHTML = "<ul>";
for (let i = 0, f; f = files[i]; i++) {
let reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
let hexdigest = MD5_hexhash(e.target.result);
output.innerHTML += "<li>" + hexdigest + " " + theFile.name + "</li>";
}
})(f);
reader.readAsBinaryString(f);
}
output.innerHTML += "</ul>"
}
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("files").addEventListener("change", handleFileSelect, false);
}, false);
</script>
</head>
<body>
<h1>MD5 calculator</h1>
<input type="file" id="files" name="files[]" multiple /><br />
<output id="list"></output>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment