I keep getting this error when trying to decrypt a password previously encrypted:
The payload is invalid.
And this is the relevant stack trace:
#0 /home/improojf/public_html/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php(136): Illuminate\Encryption\Encrypter->getJsonPayload(NULL)
#1 /home/improojf/public_html/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php(164): Illuminate\Encryption\Encrypter->decrypt('eyJpdiI6InloT0U...', false)
#2 /home/improojf/public_html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\Encryption\Encrypter->decryptString('eyJpdiI6InloT0U...')
#3 /home/improojf/public_html/app/Models/Server.php(29): Illuminate\Support\Facades\Facade::__callStatic('decryptString', Array)
#4 /home/improojf/public_html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(473): Server->getPasswordAttribute('eyJpdiI6InloT0U...')
The biggest issue here is that a string randomly becomes NULL in the encrypter code, which makes no sense to me.
Another issue with this, is that some records just behave ad intended.
What do I use it for This is used to store passwords for smtp/pop3 servers on a database
What I tried This problem is perfectly solved by not encrypting/decrypting the password, which messes up the purpose
Does it always return error? No, in fact there are some records that behave normally
What are my guesses php artisan cache:clear might be an option as reported elsewhere, but I think there should be another solution. So far I have (untested) the following accessor while previously I only had the second try/catch
public function getPasswordAttribute($value){
try {
return Crypt::decryptString($value);
} catch (\Illuminate\Contracts\Encryption\DecryptException $e) {
\Illuminate\Support\Facades\Artisan::call('cache:clear');
}
try {
return Crypt::decryptString($value);
} catch (\Illuminate\Contracts\Encryption\DecryptException $e) {
if(app()->runningUnitTests())
return $value;
else
throw $e;
}
}