| export class EncryptionService { |
| private static readonly SECRET_SALT = "RELAY_SECURE_CBT_2026_SALT"; |
|
|
| |
| |
| |
| |
| static encrypt(rawData: string): string { |
| let result = ""; |
| for (let i = 0; i < rawData.length; i++) { |
| const charCode = rawData.charCodeAt(i); |
| const saltCode = this.SECRET_SALT.charCodeAt(i % this.SECRET_SALT.length); |
| |
| result += String.fromCharCode(charCode ^ saltCode); |
| } |
| |
| try { |
| return btoa(encodeURIComponent(result)); |
| } catch { |
| return btoa(result); |
| } |
| } |
|
|
| |
| |
| |
| static decrypt(encryptedData: string): string { |
| if (!encryptedData) return ""; |
| let rawObfuscated = ""; |
| try { |
| rawObfuscated = decodeURIComponent(atob(encryptedData)); |
| } catch { |
| try { |
| rawObfuscated = atob(encryptedData); |
| } catch { |
| return ""; |
| } |
| } |
|
|
| let result = ""; |
| for (let i = 0; i < rawObfuscated.length; i++) { |
| const charCode = rawObfuscated.charCodeAt(i); |
| const saltCode = this.SECRET_SALT.charCodeAt(i % this.SECRET_SALT.length); |
| result += String.fromCharCode(charCode ^ saltCode); |
| } |
| return result; |
| } |
|
|
| |
| |
| |
| static encryptObject(obj: any): string { |
| try { |
| const rawString = JSON.stringify(obj); |
| return this.encrypt(rawString); |
| } catch { |
| return ""; |
| } |
| } |
|
|
| |
| |
| |
| static decryptObject<T = any>(encryptedStr: string): T | null { |
| if (!encryptedStr) return null; |
| try { |
| const rawString = this.decrypt(encryptedStr); |
| return JSON.parse(rawString) as T; |
| } catch { |
| return null; |
| } |
| } |
| } |
|
|