fu
Last active
January 16, 2018 18:39
-
-
Save acidsound/406f1ba0275a8d7a27a24e9d08eb69a4 to your computer and use it in GitHub Desktop.
file to sha256hash
This file contains hidden or 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
license: gpl-3.0 | |
height: 600 |
This file contains hidden or 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
blobToHash = (blob, cb)-> | |
fileReader = new FileReader | |
fileReader.onload = (event)-> | |
cb asmCrypto.SHA256.bytes event.target.result | |
fileReader.readAsArrayBuffer blob | |
document.addEventListener 'DOMContentLoaded', -> | |
document.getElementById 'fileUpload' | |
.addEventListener 'change', (e)-> | |
blobToHash e.currentTarget.files[0], (hash)-> | |
document.getElementById 'fileHash' | |
.textContent = Array.from hash | |
.map (o)-> o.toString 16 | |
.join '' | |
document.getElementById 'url2hash' | |
.addEventListener 'submit', (e)-> | |
fetch document.getElementById('url').value | |
.then (response)-> | |
response.blob() | |
.then (blob)-> | |
blobToHash blob, (hash)-> | |
document.getElementById 'urlHash' | |
.textContent = Array.from hash | |
.map (o)-> o.toString 16 | |
.join '' | |
e.preventDefault() |
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>AsmCrypto</title> | |
<meta name="description" content="media to Hash"> | |
<link rel="stylesheet" href="https://cdn.rawgit.com/acidsound/Tle-CSS/master/dist/tle.css"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/asmCrypto/0.0.11/asmcrypto.js"></script> | |
<script src="index.js"></script> | |
</head> | |
<body> | |
<form id="blob2hash" action="#"> | |
<div> | |
<label for="fileUpload">uniq fileID</label> | |
<input id="fileUpload" type="file"> | |
</div> | |
<label for="fileHash">fileHash</label> | |
<div> | |
<textarea id="fileHash"></textarea> | |
</div> | |
</form> | |
<form id="url2hash" action="#"> | |
<div> | |
<label for="url">uniq URLID</label> | |
<input id="url" type="text"> | |
</div> | |
<button id="getUrlButton">get URL</button> | |
</form> | |
<label for="urlHash">urlHash</label> | |
<div> | |
<textarea id="urlHash"></textarea> | |
</div> | |
</body> | |
</html> |
This file contains hidden or 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
/* | |
* decaffeinate suggestions: | |
* DS102: Remove unnecessary code created because of implicit returns | |
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md | |
*/ | |
const blobToHash = function(blob, cb){ | |
const fileReader = new FileReader; | |
fileReader.onload = event=> cb(asmCrypto.SHA256.bytes(event.target.result)); | |
return fileReader.readAsArrayBuffer(blob); | |
}; | |
document.addEventListener('DOMContentLoaded', function() { | |
document.getElementById('fileUpload') | |
.addEventListener('change', e=> | |
blobToHash(e.currentTarget.files[0], hash=> | |
document.getElementById('fileHash') | |
.textContent = Array.from(hash).map(o=>o.toString(16)).join('') | |
) | |
); | |
return document.getElementById('url2hash') | |
.addEventListener('submit', function(e){ | |
fetch(document.getElementById('url').value) | |
.then(response=> response.blob()).then(blob=> | |
blobToHash(blob, hash=> | |
document.getElementById('urlHash') | |
.textContent = Array.from(hash).map(o=>o.toString(16)).join('') | |
) | |
); | |
return e.preventDefault(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment