VUE sha
by ckissi
HTML
<script src="https://cdn.jsdelivr.net/gh/emn178/js-sha3/build/sha3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.21/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/emn178/js-sha512/build/sha512.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/emn178/hi-base32/build/base32.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/emn178/js-crc/build/crc.min.js"></script>
<div id="app">
<h2>Todos:</h2>
<input id="attachment" type="file">
<input name="daco" type="text" v-on:keyup="chng" v-model="value" value="{{ value }}">
<textarea name="result" type="text" v-model='result' rows=10 cols=50>{{ result }}</textarea>
<p>{{ value }}</p>
</div>
JavaScript
new Vue({
el: '#app',
data: {
value: '',
result: '',
},
methods: {
chng: function (event) {
this.result = base32.encode(this.value);
}
}
});
//Event Listener tied to the file input field
document.getElementById('attachment').addEventListener('change', eventHandler, false)
/**
*Description: Simple method to handle an event
*and fire off a function
**/
function eventHandler(evt){
var file = evt.target.files[0];
fileHash( file, sha512, function(x){
console.log( x );
});
}
/**
*Description: The actual function to calculate the hash
*Arguments:
*file: a file from a file input load event
*hasher: hashing algorithm
*callback: function that does something with the hash
**/
function fileHash( file, hasher, callback ){
//Instantiate a reader
var reader = new FileReader();
//What to do when we gets data?
reader.onload = function( e ){
var hash = hasher(e.target.result);
callback( hash );
}
reader.readAsArrayBuffer( file );
}
console.log(shake_256('aa'));