aes.js: fix salt changing even when not used

This commit is contained in:
dogeystamp 2023-01-03 21:09:00 -05:00
parent f49f072fab
commit 76fd0c0a1c
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38

View File

@ -88,17 +88,9 @@ function getKey(keyMaterial, salt) {
}
encButton.handle.addEventListener("click", async function() {
let salt;
if (encSalt.enabledFunc()) {
salt = encSalt.value;
} else {
salt = window.crypto.getRandomValues(new Uint8Array(16));
encSalt.value = salt;
}
let keyMaterial = await getKeyMaterial(encPass.value);
let key;
let salt;
if (encManualKey.value) {
key = await window.crypto.subtle.importKey(
"raw",
@ -108,6 +100,13 @@ encButton.handle.addEventListener("click", async function() {
["encrypt", "decrypt"]
);
} else {
if (encSalt.enabledFunc()) {
salt = encSalt.value;
} else {
salt = window.crypto.getRandomValues(new Uint8Array(16));
encSalt.value = salt;
}
key = await getKey(keyMaterial, salt);
encKey.value = await window.crypto.subtle.exportKey("raw", key);
}