Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save akaNightmare/30985da516873f6d8d5b18b1877f325d to your computer and use it in GitHub Desktop.
Save akaNightmare/30985da516873f6d8d5b18b1877f325d to your computer and use it in GitHub Desktop.
@fangforever
Copy link

Hi, I ran into your code, and I am trying to use it to decrypt asp.net 4.5 auth cookie. I am using aes-256-cbc and with node 8.11.1. But I can't get it work, any suggestion? thank you

@mdmsazm
Copy link

mdmsazm commented Oct 21, 2021

For aes-256-cbc, use .slice(32) instead of .slice(24) in line no. 58.
Also, your user data might be encoded in a different format in the cookie, so use decoded.substr() accordingly from line number 66.

@mdmsazm
Copy link

mdmsazm commented Oct 21, 2021

The "aes-256-cbc" version of the above code.

const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(this.decryptionKey, 'hex'), Buffer.alloc(16));
let decoded = Buffer.from(decipher.update(cookie, 'binary', 'binary') + decipher.final(), 'binary').slice(32);

let dotnetTicks = parseInt(this.__reverseHexString(decoded.slice(11, 19).toString('hex')), 16);
console.log('.net ticks ', dotnetTicks);
const utcExpireTicks = Math.floor((dotnetTicks - baseTicks) / 10000);
const isPersistent = parseInt(decoded.slice(19, 20).toString('hex'), 16);

decoded = decoded.toString('utf8').replace(/\0/g, '');

// user data format here is json
let decodedData =  decoded.substring(decoded.lastIndexOf('{'), decoded.lastIndexOf('}') + 1);
let userObj = JSON.parse(decodedData);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment