-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
44 lines (39 loc) · 1.57 KB
/
app.ts
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
import {
init,
encryptString,
decryptString,
generateKey,
generateNonce,
} from "./crypto.js";
addEventListener("DOMContentLoaded", async () => {
await init();
const generatedKey = generateKey();
const generatedNonce = generateNonce();
const key = document.getElementById("key");
if (key) key.innerHTML = generatedKey;
const nonce = document.getElementById("nonce");
if (nonce) nonce.innerHTML = generatedNonce;
const encryptButton = document.getElementById("encrypt");
const decryptButton = document.getElementById("decrypt");
// prettier-ignore
const encryptPlaintextInput = document.getElementById("encrypt-plaintext") as HTMLInputElement;
// prettier-ignore
const decryptPlaintextInput = document.getElementById("decrypt-plaintext") as HTMLInputElement;
const encryptedOutput = document.getElementById("encrypted-output");
const decryptedOutput = document.getElementById("decrypted-output");
encryptButton?.addEventListener("click", () => {
if (encryptPlaintextInput?.value && encryptedOutput) {
// prettier-ignore
const output = encryptString(encryptPlaintextInput.value, generatedKey, generatedNonce);
encryptedOutput.innerHTML = output;
if (decryptPlaintextInput) decryptPlaintextInput.value = output;
}
});
decryptButton?.addEventListener("click", () => {
if (decryptPlaintextInput?.value && decryptedOutput) {
// prettier-ignore
const output = decryptString(decryptPlaintextInput.value, generatedKey, generatedNonce);
if (decryptedOutput) decryptedOutput.innerHTML = output;
}
});
});