added decoder
This commit is contained in:
parent
104bebb783
commit
748cce0eeb
4 changed files with 22 additions and 0 deletions
17
apps/stock/data-ingestion/src/handlers/te/shared/decode.ts
Normal file
17
apps/stock/data-ingestion/src/handlers/te/shared/decode.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { inflate } from 'pako';
|
||||
|
||||
/**
|
||||
* Decodes TE obfuscated data: base64 decode -> XOR with key -> inflate -> JSON parse
|
||||
*/
|
||||
export function decodeTEData<T = unknown>(b64Data: string, key: string): T | null {
|
||||
try {
|
||||
const raw = Array.from(atob(b64Data), (c) => c.charCodeAt(0));
|
||||
const keyBytes = Array.from(new TextEncoder().encode(key));
|
||||
const keyLen = keyBytes.length;
|
||||
const xored = new Uint8Array(raw.map((byte, i) => byte ^ (keyBytes[i % keyLen] ?? 0)));
|
||||
|
||||
return JSON.parse(inflate(xored, { to: 'string' }));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
export * from './config';
|
||||
export * from './decode';
|
||||
export * from './types';
|
||||
Loading…
Add table
Add a link
Reference in a new issue