wim91's avatar

Is it possible to catch the "Crypt" exception?

Hello everyone. I've implemented encryption and decryption using the Crypt facade and started testing. I noticed that if I make changes to the encrypted token in a hidden field on the client side, I get the error

Illuminate\Contracts\Encryption\DecryptException The payload is invalid.

when attempting to decrypt. I tried catching exceptions, and this is what it looks like

try {
          $decrypted = Crypt::decryptString($req->eq);
      } catch (DecryptException $e) {
          $decrypted = 'Error!';
      }
dd($decrypted);

I'd like to redirect users to a 404 page when there's a decryption error. Could you please tell me how to solve this?

0 likes
1 reply

Please or to participate in this conversation.