DEV Community

JohnDivam
JohnDivam

Posted on • Edited on

Encrypt and Decrypt String in Laravel

In Laravel, you can use the built-in encryption and decryption features provided by the Illuminate Encryption package. This package allows you to easily encrypt and decrypt strings using various encryption algorithms. Here's a step-by-step guide on how to encrypt and decrypt strings in Laravel

Encrypting Messages:

use Illuminate\Support\Facades\Crypt;

$message = "This is a secret message";
$encryptedMessage = Crypt::encryptString($string);

Enter fullscreen mode Exit fullscreen mode

Decrypting Messages:

$decryptedMessage = Crypt::decryptString($encryptedMessage);
Enter fullscreen mode Exit fullscreen mode

Generating an encryption key

php artisan key:generate
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay