我正在尝试从 NodeJS 上标头的 Cookie 中获取 Laravel 会话 ID。
到目前为止我已经尝试过:
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);
但到目前为止我一直在得到Invalid IV length 32
.
YourSecretKey!!!
是在app.php
拉拉维尔 4.
Laravel 加密机制:
protected $cipher = 'rijndael-256';
protected $mode = 'cbc';
protected $block = 32;
...
$payload = $this->getJsonPayload($payload);
$value = base64_decode($payload['value']);
$iv = base64_decode($payload['iv']);
return unserialize($this->stripPadding($this->mcryptDecrypt($value, $iv)));
...
return mcrypt_decrypt($this->cipher, $this->key, $value, $this->mode, $iv);
...
$this->app->bindShared('encrypter', function($app)
{
return new Encrypter($app['config']['app.key']);
});
其他尝试
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');
这不会给出错误,但仍然得到无用的数据。