From: Ardis Lu Date: Sat, 28 Mar 2026 06:21:12 +0000 (-0700) Subject: Use `Uint8Array.toBase64()` instead of `btoa` X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=08eab03943f4f698589d2821a7538f2c6e26b2e1;p=static-encrypt-passkey Use `Uint8Array.toBase64()` instead of `btoa` --- diff --git a/index.html b/index.html index bdc0f33..b6c3b4b 100644 --- a/index.html +++ b/index.html @@ -12,7 +12,7 @@ - + static-encrypt-passkey diff --git a/script.js b/script.js index a0ad452..093f5d6 100644 --- a/script.js +++ b/script.js @@ -105,13 +105,8 @@ export async function encrypt(plaintext) { buffer.set(salt); buffer.set(iv, salt.byteLength); buffer.set(ciphertext, salt.byteLength + iv.byteLength); - let binary = ''; - for (let i = 0; i < buffer.byteLength; i++) { - binary += String.fromCharCode(buffer[i]); - } - const content = btoa(binary); - return content; + return buffer.toBase64(); } /** @@ -123,7 +118,7 @@ export async function encrypt(plaintext) { */ export async function decrypt(content) { // Extract random values - const buffer = Uint8Array.from(atob(content), c => c.charCodeAt(0)); + const buffer = Uint8Array.fromBase64(content); const salt = buffer.slice(0, 64); // For HKDF const iv = buffer.slice(64, 76); // For AES-GCM const ciphertext = buffer.slice(76);