aes.js: improved error handling

This commit is contained in:
dogeystamp 2023-01-02 15:01:19 -05:00
parent 1f141ccbad
commit 1d9f304830
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38

View File

@ -77,9 +77,18 @@ async function encrypt() {
async function decrypt() {
let msgEncoded = decMsg.value;
let ciphertext = new b64ToBuf(msgEncoded.ciphertext);
let iv = new Uint8Array(b64ToBuf(msgEncoded.iv));
let salt = new Uint8Array(b64ToBuf(msgEncoded.salt));
let ciphertext, iv, salt;
try {
ciphertext = new b64ToBuf(msgEncoded.ciphertext);
iv = new Uint8Array(b64ToBuf(msgEncoded.iv));
salt = new Uint8Array(b64ToBuf(msgEncoded.salt));
} catch (e) {
decMsg.alertBox("alert-error", "Invalid base64 value.");
}
if (ciphertext === undefined || iv === undefined || salt === undefined) {
return;
}
let keyMaterial = await getKeyMaterial(decPass.value);
let key = await getKey(keyMaterial, salt);