Cansu Koç
Cansu Koç

Reputation: 11

Laravel 8 decrypt

I try to do decrypt value ? But it is giving this error. The payload is invalid.

use Illuminate\Support\Facades\Crypt;
use Illuminate\Contracts\Encryption\DecryptException;

$identity_no = "eyJpdiI6Inhzakt4SE10Mk1TbGVNakZKb29nc2c9PSIsInZhbHVlIjoiaW9tWGVhOXZaQWlCYzhBbmNrbTV3dXdQYmNrTmt1S3dHKzdqelNLcFppbVJoR2s3NmptaVlKaU4rc1NSU3F2MW1oSVlJdU9OTEJuT05w ▶";

$decrypted_identityno = Crypt::decryptString($identity_no);


dd($decrypted_identityno);
die();

Upvotes: 0

Views: 1288

Answers (1)

STA
STA

Reputation: 34688

Laravel encrypting and decrypting text via OpenSSL using AES-256 and AES-128 encryption, so every time you encrypt it will give you a unique result. You can decrypt a string after you get the value from the encrypt method :

$identity_value = "1234";
$identity_no = Crypt::encryptString($identity_value);
$decrypted_identityno = Crypt::decryptString($identity_no);
dd($decrypted_identityno);

Encrypted payload must be different each time, even if the same plaintext is encrypted. Laravel does it properly

Upvotes: 2

Related Questions