-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathhash-generator.html
More file actions
106 lines (92 loc) · 2.89 KB
/
Copy pathhash-generator.html
File metadata and controls
106 lines (92 loc) · 2.89 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
!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Hash Generator - One File Tools</title>
<style>
body {
font-family: Arial, sans-serif;
background: #111827;
color: #fff;
max-width: 900px;
margin: auto;
padding: 24px;
}
textarea,
input {
width: 100%;
box-sizing: border-box;
}
textarea {
height: 180px;
padding: 10px;
margin: 10px 0;
}
.row {
display: flex;
gap: 10px;
align-items: center;
margin: 10px 0;
}
.row label {
width: 90px;
}
.row input {
flex: 1;
padding: 8px;
}
button {
padding: 8px 12px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Hash Generator</h1>
<p>SHA-1, SHA-256 and SHA-512 generator (client-side). MD5 placeholder.</p>
<textarea id="textInput" placeholder="Type text..."></textarea>
<div class="row">
<input type="file" id="fileInput" />
<label><input type="checkbox" id="upper" /> Uppercase</label>
</div>
<div class="row"><label>MD5</label><input id="md5" readonly placeholder="Not implemented" /><button onclick="copy('md5')">Copy</button></div>
<div class="row"><label>SHA-1</label><input id="sha1" readonly /><button onclick="copy('sha1')">Copy</button></div>
<div class="row"><label>SHA-256</label><input id="sha256" readonly /><button onclick="copy('sha256')">Copy</button></div>
<div class="row"><label>SHA-512</label><input id="sha512" readonly /><button onclick="copy('sha512')">Copy</button></div>
<script>
const t = document.getElementById("textInput");
const up = document.getElementById("upper");
function hex(buf) {
let h = [...new Uint8Array(buf)].map((x) => x.toString(16).padStart(2, "0")).join("");
return up.checked ? h.toUpperCase() : h;
}
async function hash(algo, text) {
return hex(await crypto.subtle.digest(algo, new TextEncoder().encode(text)));
}
async function update() {
const v = t.value;
if (!v) {
sha1.value = sha256.value = sha512.value = md5.value = "";
return;
}
sha1.value = await hash("SHA-1", v);
sha256.value = await hash("SHA-256", v);
sha512.value = await hash("SHA-512", v);
md5.value = "Requires MD5 polyfill";
}
t.oninput = update;
up.onchange = update;
fileInput.onchange = async (e) => {
const f = e.target.files[0];
if (!f) return;
t.value = await f.text();
update();
};
function copy(id) {
const el = document.getElementById(id);
if (el.value) navigator.clipboard.writeText(el.value);
}
</script>
</body>
</html>