diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-06-03 15:26:26 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-06-03 15:26:26 -0700 |
| commit | 818db3ef4aadf489dba5ba8ba4f3bb4e150f0b22 (patch) | |
| tree | 0a79f0d61a8738e5083a3ad72f5c3242a6869829 /server | |
| parent | 495ecca361a7422e7c42dea04a08946cfceef29a (diff) | |
change from aes-gcm to xor shift obfuscation
encryption was pain in the ass on cross platform
Diffstat (limited to 'server')
| -rw-r--r-- | server/index.ts | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/server/index.ts b/server/index.ts index afe8d81..c78352a 100644 --- a/server/index.ts +++ b/server/index.ts @@ -1,6 +1,4 @@ import express from 'express'; -import path from 'path'; -import crypto from 'crypto'; import { songs } from './data/songs'; import { startDate } from './data/startDate'; import cors from 'cors'; @@ -14,27 +12,28 @@ app.use(express.json()); const SERVER_PORT = process.env.SERVER_PORT || 3001; const SALT = process.env.VITE_HEARDLE_SALT ?? 'changeme'; -function getDailyKey(): Buffer { +function getObfuscationKey(): Buffer { const date = new Date().toISOString().split('T')[0]; - return crypto.pbkdf2Sync(date, SALT, 100_000, 32, 'sha256'); + return Buffer.from(SALT + date); +} + +function xorBuffer(data: Buffer, key: Buffer): Buffer { + const output = Buffer.alloc(data.length); + for (let i = 0; i < data.length; i++) { + output[i] = data[i] ^ key[i % key.length]; + } + return output; } app.get('/today', (_req, res) => { const msInDay = 86_400_000; const index = Math.floor((Date.now() - startDate.getTime()) / msInDay); const song = songs[index % songs.length]; - - const key = getDailyKey(); - const iv = crypto.randomBytes(12); - const cipher = crypto.createCipheriv('aes-256-gcm', key, iv); - const encrypted = Buffer.concat([ - cipher.update(JSON.stringify(song), 'utf8'), - cipher.final(), - ]); + const obfuscationKey = getObfuscationKey(); + const songJson = JSON.stringify(song); + const obfuscatedData = xorBuffer(Buffer.from(songJson, 'utf8'), obfuscationKey); res.json({ - iv: iv.toString('hex'), - tag: cipher.getAuthTag().toString('hex'), - data: encrypted.toString('hex'), + data: obfuscatedData.toString('hex'), }); }); |
