Created
September 4, 2023 07:31
-
-
Save kenkoooo/40828c99d5b18deaa718fb3905532b15 to your computer and use it in GitHub Desktop.
Decrypt the Rails session cookie in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function decrypt_session(cookie) { | |
const SALT = "authenticated encrypted cookie"; | |
const secret = crypto.pbkdf2Sync(secret_key_base, SALT, 1000, 32, 'sha1'); | |
const [data, iv, auth_tag] = cookie.split('--').map(s => Buffer.from(s, 'base64')); | |
const decipher = crypto.createDecipheriv('aes-256-gcm', secret, iv); | |
decipher.setAuthTag(auth_tag); | |
let decrypted_data = decipher.update(data); | |
decrypted_data = Buffer.concat([decrypted_data, decipher.final()]); | |
console.log(decrypted_data.toString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment