-
Notifications
You must be signed in to change notification settings - Fork 1
/
secret-hash.html
89 lines (66 loc) · 2.44 KB
/
secret-hash.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="cache-control" content="max-age=0">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="cache-control" content="no-store">
<meta http-equiv="pragma" content="no-cache" />
<title>Encode SHA</title>
<script type="text/javascript" src="lib/jquery.min.js"></script>
<style type="text/css">
.shares_input {
text-align:center;
}
.firstC {
width:75px;
}
th, td {
border: 1px solid black;
}
th {
text-align:center;
}
</style>
</head>
<body>
<h2>Input:</h2>
<input required type="text" autocomplete="off" class="encode_sha_param" id="encode_sha_form" autocomplete="off" style="width:80%">
<br><br>
<strong>Function:</strong>
<select class="encode_function" id="encode_function" required>
<option selected value="SHA-512">SHA-512</option>
<option value="SHA-256">SHA-256</option>
</select>
<br><br>
<div>
<strong>Iterations:</strong>
<br>
<input type="number" id="encode_iterations" class="encode_iterations" min="1" step="1" value="1" autocomplete="off">
<br>
</div>
<br>
<input type="button" value="Submit" id="valid_button">
<br><br><hr><br>
<h2>Hash:</h2>
<div id="sha_result" style="font-weight:bold;color:blue;background-color:yellow;width:85%;word-break:break-all;margin:auto;">??????</div>
<script type="text/javascript">
async function digestMessage(message, hashFunction) {
var msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
var hashBuffer = await crypto.subtle.digest(hashFunction, msgUint8); // hash the message
var hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
var hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string
return hashHex;
}
$("#valid_button").on("click",(async function(){
var hashFunction = $("#encode_function").val();
var digestHex = $("#encode_sha_form").val();
var iteration = parseInt($("#encode_iterations").val());
for (let i = 0; i < iteration; i++) {
digestHex = await digestMessage(digestHex, hashFunction);
}
$("#sha_result").html(digestHex.toUpperCase());
}));
</script>
</body>
</html>