Skip to content

Instantly share code, notes, and snippets.

@fzn0x
Forked from eungjun-yi/sha1sum.html
Created October 18, 2021 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fzn0x/9e0a4eeaf69f11cec5dafa2e66b42df2 to your computer and use it in GitHub Desktop.
Save fzn0x/9e0a4eeaf69f11cec5dafa2e66b42df2 to your computer and use it in GitHub Desktop.
<html>
<!-- You may need to download them from https://github.com/brix/crypto-js/tree/release-3.1.2/build -->
<script src="rollups/sha1.js"></script>
<script src='components/lib-typedarrays-min.js'></script>
<body>
<script>
function sha1sum() {
var oFile = document.getElementById('uploadFile').files[0];
var sha1 = CryptoJS.algo.SHA1.create();
var read = 0;
var unit = 1024 * 1024;
var blob;
var reader = new FileReader();
reader.readAsArrayBuffer(oFile.slice(read, read + unit));
reader.onload = function(e) {
var bytes = CryptoJS.lib.WordArray.create(e.target.result);
sha1.update(bytes);
read += unit;
if (read < oFile.size) {
blob = oFile.slice(read, read + unit);
reader.readAsArrayBuffer(blob);
} else {
var hash = sha1.finalize();
console.log(hash.toString(CryptoJS.enc.Hex)); // print the result
}
}
}
</script>
<form name="uploadForm">
<input id="uploadFile" type="file" onchange="sha1sum();" />
<input type="submit" value="Send" />
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment