]> git.ardis.lu - static-encrypt/commitdiff
Use `.toBase64()` and `.fromBase64()` instead of `btoa()` and `atob()`
authorArdis Lu <ardisglu@gmail.com>
Wed, 18 Mar 2026 06:54:42 +0000 (23:54 -0700)
committerArdis Lu <ardisglu@gmail.com>
Wed, 18 Mar 2026 06:54:42 +0000 (23:54 -0700)
These functions are baseline as of September 2025.

decrypt.js
encrypt.js

index a44f8f9003537ec95624b24ae74cf7e28c08f22a..0fecff4e3acaeb084e901afe685f6b0c02cdd737 100644 (file)
@@ -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);
index f86eceaf10ff2251f6603f8fc365d980e1352d04..8f9c544a824c0e801d0c5cd712e62a7524ffd1ae 100644 (file)
@@ -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
This page took 0.037075 seconds and 4 git commands to generate.