From 18a58786ac860faaef7cedb500ace903c38a1b5b Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Tue, 3 Jan 2023 21:50:27 -0500 Subject: [PATCH] aes.js: bugfixes decryption is no longer broken with custom keys --- scripts/aes.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/scripts/aes.js b/scripts/aes.js index e3b6c02..ff4b665 100644 --- a/scripts/aes.js +++ b/scripts/aes.js @@ -54,7 +54,21 @@ let decMsg = decForm.createTextArea({ label: "Encrypted message", dataType: "json-b64", }); -let decPass = decForm.createPasswordInput({label: "Password"}); +let decPass = decForm.createPasswordInput({ + label: "Password", + enabledFunc: function() {return !decManualKey.value} +}); +let decKey = decForm.createMediumTextBox({ + label: "Key", + dataType: "b64", + advanced: true, + enabled: false, + enabledFunc: function() {return decManualKey.value} +}); +let decManualKey = decForm.createCheckBox({ + label: "Use fixed key instead of password", + advanced: true +}); let decButton = decForm.createButton({label: "Decrypt"}); let decOut = decForm.createOutput({label: "Output"}); @@ -90,7 +104,8 @@ function getKey(keyMaterial, salt) { encButton.handle.addEventListener("click", async function() { let keyMaterial = await getKeyMaterial(encPass.value); let key; - let salt; + let salt = encSalt.value; + if (encManualKey.value) { key = await window.crypto.subtle.importKey( "raw", @@ -157,7 +172,18 @@ decButton.handle.addEventListener("click", async function() { } let keyMaterial = await getKeyMaterial(decPass.value); - let key = await getKey(keyMaterial, salt); + let key; + if (decManualKey.value) { + key = await window.crypto.subtle.importKey( + "raw", + decKey.value, + {"name": "AES-GCM"}, + true, + ["encrypt", "decrypt"] + ); + } else { + key = await getKey(keyMaterial, salt); + } let plaintext;