Laravel 9 How To Encrypt and Decrypt String Tutorial

Reading Time: 3 minutes

Inside this article we will see the concept i.e Laravel 9 How To Encrypt and Decrypt String Tutorial. Article contains the classified information about How to work with Encryption and decryption methods using Laravel concept.

Creating a strong and secured encrypted string is very common in web applications. Encrypted string values transmits your data without any loop hole. Every websites which do data transmission type services offers work in these process.

Laravel provides some helpful Facade class which do exactly same what we are looking here for. How to encrypt and decrypt a string in Laravel we will understand from this tutorial.

Read More: jQuery How To Create Auto Resize Textarea Example Tutorial

Let’s get started.

Laravel Installation

Open terminal and run this command to create a laravel project.

composer create-project laravel/laravel myblog

It will create a project folder with name myblog inside your local system.

To start the development server of laravel –

php artisan serve


Assuming laravel already installed inside your system.

How To Encrypt a String

To encrypt a string value we use encryptString() of Crypt Facade.

Import Facade class

use Illuminate\Support\Facades\Crypt;

Method to encrypt


How To Decrypt a String

To decrypt a string value we use decryptString() of Crypt Facade.

Read More: JQuery Limit the Number of Characters Per Line in Textarea

Method to decrypt


How To Use in Application

Suppose, we have any controller.

namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Crypt;
class UsersController extends Controller
   public function encrypt()
        $encrypted = Crypt::encryptString('onlinewebtutor');
   public function decrypt()
         $decrypt= Crypt::decryptString('eyJpdiI6Iis0UEJVSVN3WWVFV...');


Plain Text: onlinewebtutor

Once, you use encryption method you will get this encrypted value and vice versa.


We hope this article helped you to learn Laravel 9 How To Encrypt and Decrypt String Tutorial in a very detailed way.

Read More: Javascript How To Create Auto Resize Textarea Example Tutorial

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.