mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Fix crypto module
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user