From 8ed731bf6e8e6e24473cb548553e551dd73a94c8 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Tue, 17 Mar 2026 23:54:42 -0700 Subject: [PATCH] Use `.toBase64()` and `.fromBase64()` instead of `btoa()` and `atob()` These functions are baseline as of September 2025. --- decrypt.js | 2 +- encrypt.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 -- 2.47.3