e4rthdog
e4rthdog

Reputation: 5223

Encrypt database field using user passord as part of the procedure in Laravel

Laravel 5.0

I want to encrypt some data in the database using not only the application key but also the users password or any other string that HE will provide.

The reason is that i want only him to be able to decrypt the data.

How would i go about it?

-Use Javascript and encrypt the password locally and then send it to the server?

or

-Send the text that user enters directly to the server?

All traffic will be upon HTTPS

Upvotes: 0

Views: 805

Answers (1)

Brian
Brian

Reputation: 351

// Encrypt
$key = md5(Config::get('app.key') . $userString);
Crypt::setKey($key);
$encypted = Crypt::encrypt($input);

// decrypt
$key = md5(Config::get('app.key') . $userString);
Crypt::setKey($key);
$decypted = Crypt::decrypt($encypted);

Upvotes: 4

Related Questions