Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lararocks's avatar

Crypt::decrypt error

Hi,

I have a CardsController that encrypts the card number on the store method like this:

$input = Request::all();
$input['card_number'] = \Crypt::encrypt($input['card_number']);

The above works great.

But when I try to decrypt the card number in the view method, I get an error saying "DecryptException in BaseEncrypter.php line 45: The payload is invalid."

Here is my code:

$card = Card::findOrFail($id);
$card['card_number'] = \Crypt::decrypt($card->card_number);

Any idea? Thanks

0 likes
4 replies
Snapey's avatar
Snapey
Best Answer
Level 122

I hope these are not credit cards =:-\

The problem might be in the storage rather than the retrieval?

Have you checked that there is actually encrypted data in the column?

Is the column big enough (I guess that would throw an error)

Have you added card_number to the $fillable array?

1 like
lararocks's avatar

Hi,

They are not actually credit cards but they are some kind of prepaid cards.

Yes, the column data is encrypted. The card_number is already added to the $fillable array, and the DB field is big enough.

Thanks

lararocks's avatar

Just increased the length of the database field and it worked fine. Seems like it wasn't big enough to hold the encryption text.

Thank you

Please or to participate in this conversation.