title: Sharing laravel 4 session with nodejs express
body: <p>I am trying to get the laravel session id from the cookie on the header on nodejs.</p>
  
  <p>I have tried so far:</p>
  
  <pre><code>function nodeDecrypt(data, key, iv) {
    var decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
    var chunks = []
    chunks.push(decipher.update(chunk.toString(),'hex','binary'))
    chunks.push(decipher.final('binary'))
    return chunks.join('')
  }
  
  var cookie = JSON.parse(new Buffer(req.cookies.gjsess, 'base64'));
  var iv     = new Buffer(cookie.iv, 'base64');
  var value  = new Buffer(cookie.value, 'base64');
  
  var dec = nodeDecrypt(value, 'YourSecretKey!!!', iv);
  </code></pre>
  
  <p>But so far I keep getting <code>Invalid IV length 32</code>.</p>
  
  <p><code>YourSecretKey!!!</code> is the key found on the <code>app.php</code> of laravel 4.</p>
  
  <hr>
  
  <p>Laravel encryption mech:</p>
  
  <pre><code>protected $cipher = 'rijndael-256';
  protected $mode = 'cbc';
  protected $block = 32;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>$payload = $this-&gt;getJsonPayload($payload);
  $value = base64_decode($payload['value']);
  $iv = base64_decode($payload['iv']);
  return unserialize($this-&gt;stripPadding($this-&gt;mcryptDecrypt($value, $iv)));
  </code></pre>
  
  <p>...</p>
  
  <pre><code>return mcrypt_decrypt($this-&gt;cipher, $this-&gt;key, $value, $this-&gt;mode, $iv);
  </code></pre>
  
  <p>...</p>
  
  <pre><code>$this-&gt;app-&gt;bindShared('encrypter', function($app)
  {
    return new Encrypter($app['config']['app.key']);
  });
  </code></pre>
  
  <hr>
  
  <p><strong>other attempts</strong></p>
  
  <pre><code>var cookie = JSON.parse(new Buffer(req.cookies.gjsess, 'base64'));
  var iv     = new Buffer(cookie.iv, 'base64');
  var value  = new Buffer(cookie.value, 'base64');
  
  var MCrypt = require('mcrypt').MCrypt;
  var desEcb = new MCrypt('rijndael-256', 'cbc');
  desEcb.open('YourSecretKey!!!');
  var plaintext = desEcb.decrypt(value, 'base64');
  </code></pre>
  
  <p>This does not give an error but still getting useless data. </p>