Skip to content

Instantly share code, notes, and snippets.

@TheIndra55
Last active March 8, 2022 15:42
Show Gist options
  • Save TheIndra55/0489088590315b102e1b0813fa21b788 to your computer and use it in GitHub Desktop.
Save TheIndra55/0489088590315b102e1b0813fa21b788 to your computer and use it in GitHub Desktop.
Discourse user-api-keys decryption
import { privateDecrypt, constants } from "crypto"
import fs from "fs"
import fetch from "node-fetch"
const input = `...`
// decrypt payload
const privateKey = fs.readFileSync("private.key")
const data = new Buffer.from(input, "base64")
const decrypted = privateDecrypt({ key: privateKey, padding: constants.RSA_PKCS1_PADDING }, data);
const payload = JSON.parse(decrypted)
console.log(payload)
// who is this?
fetch("https://forum.cfx.re/session/current.json", { headers: { "User-Api-Key": payload.key }})
.then(x => x.json())
.then(session => {
console.log(`It's ${session.current_user.username}!`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment