UNPKG

trace.ai-cli

Version:

A powerful AI-powered CLI tool

42 lines (36 loc) 1.28 kB
const ENCRYPTION_KEY = 'AlzaSyCVKlzUxK'; function encodeUnicode(str) { const utf8Bytes = new TextEncoder().encode(str); return Buffer.from(utf8Bytes).toString('base64'); } function decodeUnicode(str) { const bytes = Buffer.from(str, 'base64'); return new TextDecoder().decode(bytes); } function encryptData(data) { const jsonStr = JSON.stringify(data); // Match worker.js approach: encode to base64 then reverse const base64 = Buffer.from( Array.from(new TextEncoder().encode(jsonStr)) .map(byte => String.fromCharCode(byte)) .join('') ).toString('base64'); return base64.split('').reverse().join(''); } function decryptData(encoded) { try { // Match worker.js approach: reverse then decode const reversed = encoded.split('').reverse().join(''); const binaryStr = Buffer.from(reversed, 'base64').toString('binary'); const bytes = Uint8Array.from(binaryStr, char => char.charCodeAt(0)); const decoded = new TextDecoder().decode(bytes); return JSON.parse(decoded); } catch (error) { console.error('Decryption failed:', error); throw new Error('Invalid encrypted data'); } } module.exports = { encryptData, decryptData };