-
Notifications
You must be signed in to change notification settings - Fork 352
/
hashHMAC.html
174 lines (171 loc) · 7.36 KB
/
hashHMAC.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
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
<html>
<link rel="stylesheet" href="gaggle.css">
<head>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>jsSHA - SHA Hashes in JavaScript</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="sha.js"></script>
<script type="text/javascript">
function calcHash() {
try {
var hashInput = document.getElementById("hashInputText");
var hashInputType = document.getElementById("hashInputType");
var hashVariant = document.getElementById("hashVariant");
var hashRounds = document.getElementById("hashRounds");
var hashOutputType = document.getElementById("hashOutputType");
var hashOutput = document.getElementById("hashOutputText");
var hashObj = new jsSHA(
hashVariant.options[hashVariant.selectedIndex].value,
hashInputType.options[hashInputType.selectedIndex].value,
{numRounds: parseInt(hashRounds.value, 10)}
);
hashObj.update(hashInput.value);
hashOutput.value = hashObj.getHash(hashOutputType.options[hashOutputType.selectedIndex].value);
} catch(e) {
hashOutput.value = e.message
}
}
function calcHMAC() {
try {
var hmacText = document.getElementById("hmacInputText");
var hmacTextType = document.getElementById("hmacTextType");
var hmacKeyInput = document.getElementById("hmacInputKey");
var hmacKeyInputType = document.getElementById("hmacKeyType");
var hmacVariant = document.getElementById("hmacVariant");
var hmacOutputType = document.getElementById("hmacOutputType");
var hmacOutput = document.getElementById("hmacOutputText");
var hmacObj = new jsSHA(
hmacVariant.options[hmacVariant.selectedIndex].value,
hmacTextType.options[hmacTextType.selectedIndex].value
);
hmacObj.setHMACKey(
hmacKeyInput.value,
hmacKeyInputType.options[hmacKeyInputType.selectedIndex].value
);
hmacObj.update(hmacText.value);
hmacOutput.value = hmacObj.getHMAC(hmacOutputType.options[hmacOutputType.selectedIndex].value);
} catch(e) {
hmacOutput.value = e.message
}
}
</script>
</head>
<body onload="calcHash();calcHMAC()">
<div id="container">
<div>
<form action="#" method="get">
<fieldset>
<legend>Hashing Demo</legend>
<div>
<label for="hashInputText">Input Text:</label><input type="text" size="75" name="hashInputText" id="hashInputText" onkeyup="calcHash()" />
</div>
<div>
<label for="hashInputType">Input Type:</label>
<select name="hashInputType" id="hashInputType" onchange="calcHash()">
<option value="B64">Base-64</option>
<option selected="selected">TEXT</option>
<option>HEX</option>
</select>
</div>
<div>
<label for="hashVariant">SHA Variant:</label>
<select name="hashVariant" id="hashVariant" onchange="calcHash()">
<option>SHA-1</option>
<option>SHA-224</option>
<option>SHA3-224</option>
<option>SHA-256</option>
<option>SHA3-256</option>
<option>SHA-384</option>
<option>SHA3-384</option>
<option>SHA-512</option>
<option>SHA3-512</option>
</select>
</div>
<div>
<label for="hashRounds">Number of Rounds:</label><input type="text" size="5" name="hashRounds" id="hashRounds" value="1" onkeyup="calcHash()" />
</div>
<div>
<label for="hashOutputType">Output Type:</label>
<select name="hashOutputType" id="hashOutputType" onchange="calcHash()">
<option value="B64">Base-64</option>
<option selected="selected">HEX</option>
</select>
</div>
<div>
<label for="hashOutputText">Output Hash:</label>
<input type="text" size="75" name="hashOutputText" id="hashOutputText" style="background-color: #b1ceed" />
</div>
</fieldset>
<fieldset>
<legend>HMAC Demo</legend>
<p>
Simply insert your text to be hashed, text type, key, key type, the SHA variant you wish to use, and the output format.<br />
<span style="font-size: 12px">Note: You may have to scroll the output text for longer length hashes</span>
</p>
<div>
<label for="hmacInputText">Input Text:</label><input type="text" size="75" name="hmacInputText" id="hmacInputText" onkeyup="calcHMAC()" />
</div>
<div>
<label for="hmacTextType">Input Type:</label>
<select name="hmacTextType" id="hmacTextType" onchange="calcHMAC()">
<option value="B64">Base-64</option>
<option selected="selected">TEXT</option>
<option>HEX</option>
</select>
</div>
<div>
<label for="hmacInputKey">Key:</label><input type="text" size="75" name="hmacInputKey" id="hmacInputKey" onkeyup="calcHMAC()" />
</div>
<div>
<label for="hmacKeyType">Key Type:</label>
<select name="hmacKeyType" id="hmacKeyType" onchange="calcHMAC()">
<option value="B64">Base-64</option>
<option selected="selected">TEXT</option>
<option>HEX</option>
</select>
</div>
<div>
<label for="hmacVariant">SHA Variant:</label>
<select name="hmacVariant" id="hmacVariant" onchange="calcHMAC()">
<option>SHA-1</option>
<option>SHA-224</option>
<option>SHA3-224</option>
<option>SHA-256</option>
<option>SHA3-256</option>
<option>SHA-384</option>
<option>SHA3-384</option>
<option>SHA-512</option>
<option>SHA3-512</option>
</select>
</div>
<div>
<label for="hmacOutputType">Output Type:</label>
<select name="hmacOutputType" id="hmacOutputType" onchange="calcHMAC()">
<option value="B64">Base-64</option>
<option selected="selected">HEX</option>
</select>
</div>
<div>
<label for="hmacOutputText">Output Hash:</label>
<input type="text" size="75" name="hmacOutputText" id="hmacOutputText" style="background-color: #b1ceed" />
</div>
</fieldset>
</form>
</div>
<div id="copyright">
Copyright © 2008-2017 <a href="https://github.com/Caligatio/">Brian Turek</a>
</div>
</div>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2442290-9']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>