From 08eab03943f4f698589d2821a7538f2c6e26b2e1 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Fri, 27 Mar 2026 23:21:12 -0700 Subject: [PATCH] Use `Uint8Array.toBase64()` instead of `btoa` --- index.html | 2 +- script.js | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) 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); -- 2.47.3