-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.html
More file actions
194 lines (163 loc) · 6.38 KB
/
Copy pathhash.html
File metadata and controls
194 lines (163 loc) · 6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<div class="d-flex flex-row flex-wrap">
<div id="hasher" class="playtile">
<div class="tile_title text-center">Hasher</div>
<div id="holder" class="d-flex justify-content-center">
<div id="busy" class="loader" style="display:none;"></div>
<div id="hasher_tip" style="display:block;">Drop a file here to get its hash.</div>
</div>
<div class="row">
<div class="col-2">file:</div>
<div class="col" id="filename">none</div>
</div >
<div class="row">
<div class="col-2">mime: </div>
<div class="col" id="mimetype">none</div>
</div >
<div class="row">
<div class="col-2">size: </div>
<div class="col" id="filesize">0</div>
<div class="col-2"> bytes </div>
</div >
<div>
<div>md5sum: </div>
<div class="hash" id="md5sum"></div>
</div>
<div>
<div>sha1: </div>
<div class="hash" id="sha1sum"></div>
</div>
<div>
<div>sha256: </div>
<div class="hash" id="sha256sum"></div>
</div>
<div>
<div> sha512: </div>
<div class="hash" id="sha512sum"></div>
</div>
</div>
</div>
<!--div id="myfilereader" class="playtile">
<div class="tile_title text-center">File Reader</div>
<input type="file" id="files" name="file" />
<br>Read bytes:<br>
<span class="readBytesButtons">
<button data-startbyte="0" data-endbyte="4">1-5</button>
<button data-startbyte="5" data-endbyte="14">6-15</button>
<button data-startbyte="6" data-endbyte="7">7-8</button>
</span>
<div id="byte_range"></div>
<div id="byte_content"></div>
</div-->
<style type="text/css">
.tile_title { margin-bottom:8px; line-height: 2em; font-size: 1.25rem;
box-shadow: inset 0 0 5px rgba(0,0,0,0.15);}
.thumb { height: 75px; border: 1px solid #000; margin: 10px 5px 0 0; }
input, button { margin: 5px; }
button { width: 100px; }
.playtile { padding: .5rem!important;
box-shadow: inset 0 0 5px rgba(0,0,0,0.15); border: 1px solid #ccc;
padding:5px; margin:5px; width:35em; min-width:35em; min-height:28em; }
#holder { border: 10px dashed #ccc; height: 5em; padding: 10px; }
#holder.hover { border: 10px dashed #333; }
.hash {overflow-wrap: break-word; box-shadow: inset 0 0 5px rgba(155,0,0,0.15); padding-left:5px;}
#byte_content { margin: 5px 0; max-height: 100px; overflow-y: auto; overflow-x: hidden; }
#byte_range { margin-top: 5px; }
.loader {
border: 0.5em solid #f3f3f3;
border-radius: 50%;
border-left: 0.5em solid #3498db;
border-top: 0.5em solid #3498db;
width: 2.75em;
height: 2.75em;
-webkit-animation: spin 2s linear infinite; /* Safari */
animation: spin 2s linear infinite;
}
/* Safari */
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); } }
</style>
<script type="application/javascript">
var holder = document.getElementById('holder');
holder.ondragover = function() {
return false;
};
holder.ondragend = function() {
return false;
};
window.addEventListener('load', function() {
var md5 = CryptoJS.MD5("").toString();
var sha1 = CryptoJS.SHA1("").toString();
var sha256 = CryptoJS.SHA256("").toString();
var sha512 = CryptoJS.SHA512("").toString();
document.getElementById('md5sum').innerHTML = md5;
document.getElementById('sha1sum').innerHTML = sha1;
document.getElementById('sha256sum').innerHTML = sha256;
document.getElementById('sha512sum').innerHTML = sha512;
});
holder.ondrop = function(event) {
event.preventDefault();
var file = event.dataTransfer.files[0];
document.getElementById('busy').style = "display:block;"
document.getElementById('hasher_tip').style = "display:none;"
document.getElementById('filename').innerHTML = file.name;
document.getElementById('mimetype').innerHTML = file.type;
document.getElementById('filesize').innerHTML = file.size
document.getElementById('md5sum').innerHTML = "00000000000000000000000000000000";
document.getElementById('sha1sum').innerHTML = "0000000000000000000000000000000000000000";
document.getElementById('sha256sum').innerHTML = "0000000000000000000000000000000000000000000000000000000000000000";
document.getElementById('sha512sum').innerHTML = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
var reader = new FileReader();
reader.onload = function(event) {
var base64String = event.target.result.split(',')[1];
var binary = CryptoJS.enc.Base64.parse(base64String);
console.log(file.name);
console.log(file.type);
console.log(file.size);
var md5 = CryptoJS.MD5(binary).toString();
var sha1 = CryptoJS.SHA1(binary).toString();
var sha256 = CryptoJS.SHA256(binary).toString();
var sha512 = CryptoJS.SHA512(binary).toString();
document.getElementById('md5sum').innerHTML = md5;
document.getElementById('sha1sum').innerHTML = sha1;
document.getElementById('sha256sum').innerHTML = sha256;
document.getElementById('sha512sum').innerHTML = sha512;
document.getElementById('busy').style = "display:none;"
document.getElementById('hasher_tip').style = "display:block;"
};
reader.readAsDataURL(file);
};
function readBlob(opt_startByte, opt_stopByte) {
var files = document.getElementById('files').files;
if (!files.length) {
alert('Please select a file!');
return;
}
var file = files[0];
var start = parseInt(opt_startByte) || 0;
var stop = parseInt(opt_stopByte) || file.size - 1;
var reader = new FileReader();
// If we use onloadend, we need to check the readyState.
reader.onloadend = function(evt) {
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
document.getElementById('byte_content').textContent = evt.target.result;
document.getElementById('byte_range').textContent =
['Read bytes: ', start + 1, ' - ', stop + 1,
' of ', file.size, ' byte file'].join('');
}
};
var blob = file.slice(start, stop + 1);
reader.readAsBinaryString(blob);
}
document.querySelector('.readBytesButtons').addEventListener('click', function(evt) {
if (evt.target.tagName.toLowerCase() == 'button') {
var startByte = evt.target.getAttribute('data-startbyte');
var endByte = evt.target.getAttribute('data-endbyte');
readBlob(startByte, endByte);
}
}, false);
</script>