From: Ardis Lu Date: Wed, 18 Mar 2026 06:54:42 +0000 (-0700) Subject: Use `.toBase64()` and `.fromBase64()` instead of `btoa()` and `atob()` X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=8ed731bf6e8e6e24473cb548553e551dd73a94c8;p=static-encrypt Use `.toBase64()` and `.fromBase64()` instead of `btoa()` and `atob()` These functions are baseline as of September 2025. --- diff --git a/decrypt.js b/decrypt.js index a44f8f9..0fecff4 100644 --- a/decrypt.js +++ b/decrypt.js @@ -9,7 +9,7 @@ export async function decrypt(content, password) { const encodedPassword = encoder.encode(password); const additionalData = encoder.encode('https://github.com/ardislu/static-encrypt'); - const contentBuffer = Uint8Array.from(atob(content), c => c.charCodeAt(0)); + const contentBuffer = Uint8Array.fromBase64(content); const salt = new Uint8Array(32); const iv = new Uint8Array(12); const ciphertext = new Uint8Array(contentBuffer.byteLength - salt.byteLength - iv.byteLength); diff --git a/encrypt.js b/encrypt.js index f86ecea..8f9c544 100644 --- a/encrypt.js +++ b/encrypt.js @@ -46,7 +46,7 @@ export async function encrypt(plaintext, password) { contentBuffer.set(salt); contentBuffer.set(iv, salt.byteLength); contentBuffer.set(ciphertext, salt.byteLength + iv.byteLength); - const content = btoa(String.fromCharCode(...contentBuffer)); + const content = contentBuffer.toBase64(); return content; } \ No newline at end of file