Fix crypto module

This commit is contained in:
2025-08-26 19:15:33 +03:00
Unverified
parent 1fb01a4404
commit ebeeaa29a6
2 changed files with 7 additions and 4 deletions
+3 -1
View File
@@ -226,7 +226,9 @@ async function loadUsers() {
if (env.senderId === activeDm.userId && env.id > maxIncomingId) {
maxIncomingId = env.id;
}
} catch {}
} catch (e) {
console.error("Error while loading message:", e);
}
}
container.scrollTop = container.scrollHeight;
if (maxIncomingId > 0) {
+4 -3
View File
@@ -11,9 +11,10 @@ export async function aesGcmEncrypt(key: CryptoKey, plaintext: Uint8Array | Arra
}
export async function aesGcmDecrypt(key: CryptoKey, iv: Uint8Array | ArrayBuffer, ciphertext: Uint8Array | ArrayBuffer): Promise<Uint8Array> {
const ivBuffer = iv instanceof Uint8Array ? iv.buffer as ArrayBuffer : iv;
const ciphertextBuffer = ciphertext instanceof Uint8Array ? ciphertext.buffer as ArrayBuffer : ciphertext;
const pt = await crypto.subtle.decrypt({ name: "AES-GCM", iv: ivBuffer }, key, ciphertextBuffer);
// WebCrypto AES-GCM requires Uint8Array for iv and data; passing ArrayBuffer slices can break auth tag boundaries
const ivBytes = iv instanceof Uint8Array ? iv : new Uint8Array(iv);
const ctBytes = ciphertext instanceof Uint8Array ? ciphertext : new Uint8Array(ciphertext);
const pt = await crypto.subtle.decrypt({ name: "AES-GCM", iv: ivBytes }, key, ctBytes);
return new Uint8Array(pt);
}