DEV Community

Websolutionstuff
Websolutionstuff

Posted on • Originally published at websolutionstuff.com

How To Encrypt And Decrypt String In Laravel 8

In this example we will see how to encrypt and decrypt string in laravel 8 using crypt helper, As we all know laravel framework provide more security to user and that's why laravel provide encrypt of password or string to user, here we will see how to encrypt or decrypt string in laravel.

You need to use Crypt class to start encryptString and decryptString or some data.

use Crypt;
use App\Model\User;
Enter fullscreen mode Exit fullscreen mode

Example 1 :

$user = new User();
$user->password = Crypt::encrypt($data['password']);
$user->save();

  public function encrypt()
   {
        $encrypted = Crypt::encryptString('websolutionstuff');
        print_r($encrypted);
   }

    public function decrypt()
    {
         $decrypt= Crypt::decryptString('your_encrypted_string');
         print_r($decrypt);
    }
Enter fullscreen mode Exit fullscreen mode

Example 2 :

$data = Request::all();

$user = new User();
$user->password = Crypt::encrypt($data['password']);
$user->save();

foreach ($user as $row)
{
  Crypt::decrypt($row->password);
}
Enter fullscreen mode Exit fullscreen mode

You May Also Like :

  1. Read Also : How To Convert PHP Array To JSON Object

  2. Read Also : How To Create Dependent Dropdown In Laravel

  3. Read Also : Github And Git Commands

Discussion (0)