|
23 | 23 | border-radius: 10px; |
24 | 24 | box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); |
25 | 25 | width: 90%; |
26 | | - max-width: 500px; |
| 26 | + max-width: 900px; |
27 | 27 | text-align: center; |
28 | 28 | } |
29 | 29 |
|
@@ -148,8 +148,58 @@ <h3>Encrypted Output:</h3> |
148 | 148 |
|
149 | 149 | <h3>Decrypted Output:</h3> |
150 | 150 | <p id="output"></p> |
| 151 | + |
| 152 | + <h3>Hash-based message authentication code (or HMAC)</h3> |
| 153 | + |
| 154 | + <label for="hmacModeSelect">Select HASH function:</label> |
| 155 | + <select id="hmacModeSelect"> |
| 156 | + <option value="sha1">SHA1</option> |
| 157 | + <option value="sha256">SHA256</option> |
| 158 | + <option value="sha384">SHA384</option> |
| 159 | + <option value="sha512">SHA512</option> |
| 160 | + </select> |
| 161 | + |
| 162 | + <label for="keyInput">Enter HMAC Key:</label> |
| 163 | + <input type="text" id="hmacKeyInput" placeholder="Enter 32-byte key"> |
| 164 | + |
| 165 | + <label for="dataInput">Enter Data to Encrypt:</label> |
| 166 | + <input type="text" id="hmacDataInput" placeholder="Enter text to encrypt"> |
| 167 | + |
| 168 | + <button onclick="hmacData()">Hash</button> |
| 169 | + |
| 170 | + <h3>HMAC Output:</h3> |
| 171 | + <p id="hmacOutput"></p> |
| 172 | + |
151 | 173 |
|
152 | 174 | <script> |
| 175 | + async function hmacData() { |
| 176 | + const key = document.getElementById("hmacKeyInput").value; |
| 177 | + const data = document.getElementById("hmacDataInput").value; |
| 178 | + const mode = document.getElementById("hmacModeSelect").value; |
| 179 | + |
| 180 | + try { |
| 181 | + let hmacOutput; |
| 182 | + switch(mode) { |
| 183 | + case "sha1": |
| 184 | + hmacOutput = await crypsi.hmac.sha1(key, data); |
| 185 | + break; |
| 186 | + case "sha256": |
| 187 | + hmacOutput = await crypsi.hmac.sha256(key, data); |
| 188 | + break; |
| 189 | + case "sha384": |
| 190 | + hmacOutput = await crypsi.hmac.sha384(key, data); |
| 191 | + break; |
| 192 | + case "sha512": |
| 193 | + hmacOutput = await crypsi.hmac.sha512(key, data); |
| 194 | + break; |
| 195 | + } |
| 196 | + |
| 197 | + document.getElementById("hmacOutput").innerText = hmacOutput; |
| 198 | + } catch (error) { |
| 199 | + document.getElementById("hmacOutput").innerText = "HMAC failed: " + error.message; |
| 200 | + } |
| 201 | + } |
| 202 | + |
153 | 203 | async function encryptData() { |
154 | 204 | const key = document.getElementById("keyInput").value; |
155 | 205 | const data = document.getElementById("dataInput").value; |
|
0 commit comments