Paul Chase
Paul Chase

Reputation: 29

How to encrypt and decrypt messages in laravel?

I want to work on a project where users can send messages to others users that are subscribe to their channels.

I want to ask if it's very necessary to encrypt the messages before storing them in the database? Although some messages may contain some sensitive information.

If yes, how do I go about encrypting the message in laravel and also decrypting it when showing it to the end user?

Upvotes: 0

Views: 1655

Answers (2)

Chandan Dubey
Chandan Dubey

Reputation: 11

use Illuminate\Support\Facades\Crypt;
$encrypted = Crypt::encryptString('Hello world.');
$decrypted = Crypt::decryptString($encrypted);

Upvotes: 1

Murat Bagsiz
Murat Bagsiz

Reputation: 103

You can check Laravel's encryption methods.

Crypt::encryptString('<string>')
Crypt::decryptString($encryptedValue)

Upvotes: 0

Related Questions