Created
November 30, 2015 20:11
-
-
Save arulprasad/30c181d43576c4c99842 to your computer and use it in GitHub Desktop.
generate md5 for a file using CryptoJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Get MD5 for a file</title> | |
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script> | |
<script type="text/javascript"> | |
function onFileSelect(){ | |
var reader = new FileReader(); | |
reader.addEventListener('load',function () { | |
var hash = CryptoJS.MD5(CryptoJS.enc.Latin1.parse(this.result)); | |
var md5 = hash.toString(CryptoJS.enc.Hex) | |
var filename = document.getElementById("input").value.split('/').pop().split('\\').pop(); | |
var output = "MD5 (" + filename + ") = " + md5 | |
console.log(output); | |
document.getElementById("md5").innerText = output | |
}); | |
reader.readAsBinaryString(document.getElementById("input").files[0]); | |
} | |
</script> | |
</head> | |
<form> | |
<input type="file" id='input' onchange='onFileSelect();'> | |
</form> | |
<pre id="md5"></pre> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks man