diff options
author | metamuffin <metamuffin@disroot.org> | 2022-09-09 19:27:18 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-09-09 19:27:18 +0200 |
commit | d71b0cb3b576e36ad4af64d40af584f05c4d89d3 (patch) | |
tree | a939a230011daa6bc8832df337fd72612264e82b /client-web/source/protocol | |
parent | 962ec1b9a0b44661e46acf81e867e81e87d53038 (diff) | |
download | keks-meet-d71b0cb3b576e36ad4af64d40af584f05c4d89d3.tar keks-meet-d71b0cb3b576e36ad4af64d40af584f05c4d89d3.tar.bz2 keks-meet-d71b0cb3b576e36ad4af64d40af584f05c4d89d3.tar.zst |
minor adjustments
Diffstat (limited to 'client-web/source/protocol')
-rw-r--r-- | client-web/source/protocol/crypto.ts | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/client-web/source/protocol/crypto.ts b/client-web/source/protocol/crypto.ts index 79b7e1d..654e80b 100644 --- a/client-web/source/protocol/crypto.ts +++ b/client-web/source/protocol/crypto.ts @@ -56,16 +56,21 @@ export async function crypto_encrypt(key: CryptoKey, data: string): Promise<stri } export async function crypt_decrypt(key: CryptoKey, data: string): Promise<string> { - const buf = base64_to_buf(data); - const iv = buf.slice(0, IV_LENGTH); - const ciphertext = buf.slice(IV_LENGTH); - const decryptedContent = await window.crypto.subtle.decrypt( - { name: "AES-GCM", iv }, - key, - ciphertext - ); - const plain = new TextDecoder().decode(decryptedContent); - return plain + try { + const buf = base64_to_buf(data); + const iv = buf.slice(0, IV_LENGTH); + const ciphertext = buf.slice(IV_LENGTH); + const decryptedContent = await window.crypto.subtle.decrypt( + { name: "AES-GCM", iv }, + key, + ciphertext + ); + const plain = new TextDecoder().decode(decryptedContent); + return plain + } catch (_e) { + log({ scope: "crypto", warn: true }, "unable to decrypt") + return "{}" // :) + } } export function base64_to_buf(data: string): Uint8Array { |