Nerdur commited on
Commit
89e672e
Β·
verified Β·
1 Parent(s): 15399e1

Upload index.html

Browse files
Files changed (1) hide show
  1. static/index.html +15 -9
static/index.html CHANGED
@@ -1325,20 +1325,23 @@ const el = (tag, attrs={}, ...children) => {
1325
 
1326
  // ─── Encryption helpers (Web Crypto API) ──────────────────────────
1327
  const Crypto = {
 
1328
  async getKey() {
1329
- const raw = 'agentscope-key-v1-' + navigator.userAgent.slice(0,20);
1330
  const enc = new TextEncoder().encode(raw);
1331
  const hash = await crypto.subtle.digest('SHA-256', enc);
1332
  return crypto.subtle.importKey('raw', hash, {name:'AES-GCM'}, false, ['encrypt','decrypt']);
1333
  },
1334
  async encrypt(text) {
1335
- const key = await this.getKey();
1336
- const iv = crypto.getRandomValues(new Uint8Array(12));
1337
- const enc = new TextEncoder().encode(text);
1338
- const ct = await crypto.subtle.encrypt({name:'AES-GCM',iv}, key, enc);
1339
- const buf = new Uint8Array(iv.length + ct.byteLength);
1340
- buf.set(iv); buf.set(new Uint8Array(ct), iv.length);
1341
- return btoa(String.fromCharCode(...buf));
 
 
1342
  },
1343
  async decrypt(b64) {
1344
  try {
@@ -1347,7 +1350,10 @@ const Crypto = {
1347
  const iv = buf.slice(0,12), ct = buf.slice(12);
1348
  const dec = await crypto.subtle.decrypt({name:'AES-GCM',iv}, key, ct);
1349
  return new TextDecoder().decode(dec);
1350
- } catch { return ''; }
 
 
 
1351
  }
1352
  };
1353
 
 
1325
 
1326
  // ─── Encryption helpers (Web Crypto API) ──────────────────────────
1327
  const Crypto = {
1328
+ // Koristimo fiksni ključ β€” userAgent mijenja pri update-u i gubi ključeve
1329
  async getKey() {
1330
+ const raw = 'agentscope-static-key-v2';
1331
  const enc = new TextEncoder().encode(raw);
1332
  const hash = await crypto.subtle.digest('SHA-256', enc);
1333
  return crypto.subtle.importKey('raw', hash, {name:'AES-GCM'}, false, ['encrypt','decrypt']);
1334
  },
1335
  async encrypt(text) {
1336
+ try {
1337
+ const key = await this.getKey();
1338
+ const iv = crypto.getRandomValues(new Uint8Array(12));
1339
+ const enc = new TextEncoder().encode(text);
1340
+ const ct = await crypto.subtle.encrypt({name:'AES-GCM',iv}, key, enc);
1341
+ const buf = new Uint8Array(iv.length + ct.byteLength);
1342
+ buf.set(iv); buf.set(new Uint8Array(ct), iv.length);
1343
+ return btoa(String.fromCharCode(...buf));
1344
+ } catch { return btoa(text); }
1345
  },
1346
  async decrypt(b64) {
1347
  try {
 
1350
  const iv = buf.slice(0,12), ct = buf.slice(12);
1351
  const dec = await crypto.subtle.decrypt({name:'AES-GCM',iv}, key, ct);
1352
  return new TextDecoder().decode(dec);
1353
+ } catch {
1354
+ // Fallback: pokuőaj starih userAgent-enkriptovanih ključeva ili plain base64
1355
+ try { return atob(b64); } catch { return ''; }
1356
+ }
1357
  }
1358
  };
1359