]> git.ardis.lu - static-encrypt-passkey/commitdiff
Use `Uint8Array.toBase64()` instead of `btoa`
authorArdis Lu <ardisglu@gmail.com>
Sat, 28 Mar 2026 06:21:12 +0000 (23:21 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sat, 28 Mar 2026 06:21:43 +0000 (23:21 -0700)
index.html
script.js

index bdc0f3398b3c752b27e1a3e7f5a4f48aae5ec81a..b6c3b4b6f614a10d605183626767a42dd68aa87b 100644 (file)
@@ -12,7 +12,7 @@
   <link rel="canonical" href="https://108117.xyz/">
   <link rel="icon" href="data:,">
   <link rel="stylesheet" href="./style.css">
-  <link rel="modulepreload" href="./script.js" integrity="sha512-ljYjSBnb58ufLJgdl8cOXJT6xnVRlzdCQWwGG2AKTZTViiH+0tHxU4k1cDsqjw/cQIvxmoIBl6WSR1bOeG+uFQ==">
+  <link rel="modulepreload" href="./script.js" integrity="sha512-Lkb5w3ts0GdkX4MFDhtyGZFN8o4PtN1u+jq0tX4XqCCN/sV+ddnsro9zNQ12vt6fSBS6NJUPUCxwqiIpNgSAMA==">
   <title>static-encrypt-passkey</title>
 </head>
 
index a0ad4520e206b2676f773e3b0fe8ca4d75182c4f..093f5d6d1f16c81a4c3b604b04019ca93fe47c28 100644 (file)
--- 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);
This page took 0.044098 seconds and 4 git commands to generate.