|
1 | 1 |
|
2 | 2 | (async function () { |
3 | 3 |
|
| 4 | + let g_urlsafe = 1 as 1|0 |
| 5 | + |
4 | 6 | interface InputData { |
5 | 7 | prefix: string; |
6 | 8 | pubkey: string; |
|
65 | 67 | try { |
66 | 68 | let te = new TextEncoder(); |
67 | 69 | let enc = await ec.encrypt(p, te.encode(text)); |
68 | | - setCipherText(ec.base64Encode(enc)); |
| 70 | + setCipherText(ec.base64Encode(enc,g_urlsafe)); |
69 | 71 | return true; |
70 | 72 | } catch (error) { |
71 | 73 | setErrMsg(error as string); |
|
111 | 113 | return; |
112 | 114 | } |
113 | 115 | try { |
114 | | - let arr = ec.base64Decode(base64); |
| 116 | + let arr = ec.base64Decode(base64,g_urlsafe); |
115 | 117 | let dec = await ec.decrypt(p, arr); |
116 | 118 | let te = new TextDecoder(); |
117 | 119 | setPlainText(te.decode(dec)); |
|
259 | 261 |
|
260 | 262 |
|
261 | 263 | let msg = ` |
| 264 | + v2 |
262 | 265 | ${G_Input?.prefix || ""} ${newLine} |
263 | 266 | 备份时间:${beijingtime()} ${newLine} |
264 | 267 |
|
|
297 | 300 |
|
298 | 301 |
|
299 | 302 | let msg = ` |
| 303 | + v2-urlsafe |
300 | 304 | ${G_Input?.prefix || ""} ${newLine} |
301 | 305 | 备份时间:${beijingtime()} ${newLine} |
302 | 306 |
|
|
334 | 338 | let jsonstring = JSON.stringify(s); |
335 | 339 | let arr = new TextEncoder().encode(jsonstring); |
336 | 340 | let dataBuff = await ec.encrypt(webPublic, arr); |
337 | | - let data = ec.base64Encode(dataBuff); |
| 341 | + let data = ec.base64Encode(dataBuff,1); |
338 | 342 |
|
339 | | - // Convert to URL-safe base64 for data2 |
340 | | - let data2 = regularBase64ToUrlSafe(data); |
341 | 343 |
|
342 | 344 | let bookmark = `${location.origin}${ |
343 | 345 | location.pathname |
344 | | - }?t=${new Date().toISOString()}#&data2=${encodeURIComponent(data2)}`; |
| 346 | + }?t=${new Date().toISOString()}#&data2=${encodeURIComponent(data)}`; |
345 | 347 |
|
346 | 348 | let a = document.createElement("a"); |
347 | 349 | a.innerText = bookmark; |
|
403 | 405 | btime.innerText = `Package:${__BUILD_MOD__} \n ${__BUILD_TIME__} `; |
404 | 406 |
|
405 | 407 |
|
406 | | - // Convert URL-safe base64 to regular base64 |
407 | | - function urlSafeBase64ToRegular(urlSafeBase64: string): string { |
408 | | - return urlSafeBase64 |
409 | | - .replace(/-/g, '+') |
410 | | - .replace(/_/g, '/'); |
411 | | - } |
412 | | - |
413 | | - // Convert regular base64 to URL-safe base64 |
414 | | - function regularBase64ToUrlSafe(regularBase64: string): string { |
415 | | - return regularBase64 |
416 | | - .replace(/\+/g, '-') |
417 | | - .replace(/\//g, '_') |
418 | | - .replace(/=/g, ''); // Remove padding |
419 | | - } |
420 | | - |
421 | 408 | (async function initDefaultValues() { |
422 | 409 |
|
423 | 410 | console.log(location.hash); |
|
428 | 415 |
|
429 | 416 | // Use data2 if available, otherwise use data |
430 | 417 | if (data2) { |
431 | | - data = urlSafeBase64ToRegular(data2); |
| 418 | + data = data2 |
| 419 | + } |
| 420 | + if (data && !data2) { |
| 421 | + g_urlsafe = 0 |
432 | 422 | } |
433 | 423 |
|
434 | 424 | if (!data) { |
|
438 | 428 | let ttlog = console.log; |
439 | 429 | ttlog({ webPrivate, webPublic }); |
440 | 430 |
|
441 | | - let plainBf = await ec.decrypt(webPrivate, ec.base64Decode(data)); |
| 431 | + let plainBf = await ec.decrypt(webPrivate, ec.base64Decode(data,g_urlsafe)); |
442 | 432 | let plain = new TextDecoder().decode(plainBf); |
443 | 433 | ttlog(plain); |
444 | 434 |
|
|
0 commit comments