Support the ongoing development of Laravel.io →
Security Requests Session

Hello,

I am having an issue with the Crypt facade in Laravel. When I execute the code below, and then refresh a page, the Session facade cannot find anything and I am assuming it is still using the new values for Crypt that I just set. I was under the impression that the Crypt facade will only take affect for one request, and then start using the default values again. I've even tried to reset the cipher, key, and mode back to default values after decrypting my value.

Does anyone see any issues with my code?

Thanks, Nate

$dns = DnsInfo::find($this->fk_id);
$company = Company::find($dns->fk_id);
$keyPrefix = $dns->tenant_code . $company->id . $dns->fk_type . $dns->id . $this->fk_type;

Crypt::setKey($keyPrefix . Config::get('app.encryption_key'));
Crypt::setCipher('rijndael-256');
Crypt::setMode('ecb');

$value = Crypt::decrypt($this->value);

return $value; 
Last updated 3 years ago.
0

I just noticed this issue also trying to set the key for the encryption. I believe this is a bug. I'm not sure if there's a way around this. I'm building an app that requires important data to be encrypted using different keys and i can store the keys related to the data somewhere else.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.