Last active
July 25, 2017 07:23
-
-
Save AleksMeshkov/10425499 to your computer and use it in GitHub Desktop.
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
// requirements | |
var PHPUnserialize = require('php-unserialize'); // npm install php-unserialize | |
var MCrypt = require('mcrypt').MCrypt; // npm install mcrypt | |
// helper function | |
function ord( string ) { // Return ASCII value of character | |
// | |
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
return string.charCodeAt(0); | |
} | |
function getSessionIdFromLaravelCookie() { | |
var cookie = JSON.parse(new Buffer(req.cookies.laravel_session, 'base64')); | |
var iv = new Buffer(cookie.iv, 'base64'); | |
var value = new Buffer(cookie.value, 'base64'); | |
var key = "_Encryption Key_"; | |
var rijCbc = new MCrypt('rijndael-256', 'cbc'); | |
rijCbc.open(key, iv); // it's very important to pass iv argument! | |
var decrypted = rijCbc.decrypt(value).toString(); | |
var len = decrypted.length - 1; | |
var pad = ord(decrypted.charAt(len)); | |
var sessionId = PHPUnserialize.unserialize(decrypted.substr(0, decrypted.length - pad)); | |
return sessionId; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting this error:
on node -v 0.10.37