I'm trying to decrypt laravel_session but the following error occur:
An error has occurred: The payload is invalid.
simply I'm using Rachet and I'm trying to call the authorized user, so I got the cookies in httpRequest using the following:
public function onOpen(ConnectionInterface $conn) {
$this->clients[$conn->resourceId] = new Client();
$this->clients[$conn->resourceId]->conn = $conn;
$cookiesRaw = $conn->httpRequest->getHeader('Cookie');
$cookies = [];
if(count($cookiesRaw))
{
$cookies = \GuzzleHttp\Psr7\parse_header($cookiesRaw)[0]; // Array of cookies
}
// Get the laravel's one
$laravelCookie = $cookies[Config::get('session.cookie')];
$idSession = Crypt::decrypt($laravelCookie);
echo "\n cookie is ";
print_r($idSession);
}
The Crypt::decrypt($laravelCookie);
is causing the error, I've tried to use:
$cookie_contents = json_decode( base64_decode( $laravelCookie, true ));
$value = base64_decode( $cookie_contents->value );
$iv = base64_decode( $cookie_contents->iv );
$clear = unserialize( \openssl_decrypt($value, \Config::get( 'app.cipher' ), \Config::get( 'app.key' ), OPENSSL_RAW_DATA, $iv));
echo "Cookie contents (Session ID): $value\n";
but it is also causing The payload is invalid.
How can I decrypt this laravel_session in order to get user session id !
I want to get the Auth user via this session.
I've searched a lot in stack-overflow and google, but all the cases didn't match mine.
Note: I'm using SESSION_DRIVER=file
Laravel provides a way to grab your session id:
use Illuminate\Support\Facades\Session;
$sessionid = Session::getId();