DEV Community

JohnDivam
JohnDivam

Posted on • Updated 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)