wwardaww/laravel-id-cryption
Laravel Id Cryption
This Trait Encrypt Your Data (from database or somewhere) or, Decrypt Your data (from client or somewhere) and it doesn't effect your real data (from data source).
Based on samwhisker/laravel-trait-encrypt
Installing
composer require wwardaww/laravel-id-cryption
Note : APP_KEY must not be empty in your .env file.
In Your Model File
- Use Trait :
use Wwardaww\Encryptable;
class YourModel extends Model
{
use Encryptable;
- Add your Encryptable columns and Hidden functions :
protected $encryptable = [
'id',
'account_id',
'profile_id',
'user_id',
'some_id'
];
protected $hiddenFunctions = [
'someDefaultFunc',
'someDefaultFunc2',
];
Usage
Example Table on Your Data Source
| ID | Name |
|---|---|
| 5 | Ahmet Oğuz |
Get Object Whit Encrypted Id
$encryptedId = "eyJpdiI6IlpxVWtpMGt4dERZbkRcL3hXVTZLKzVRPT0iLCJ2YWx1ZSI6IkhUNzF3MEFsRW1cL2tcLzVTRlZ6QmVaZz09IiwibWFjIjoiZTI5M2JiZTRiNzA2NGVjMTIwNmJhNWZjNjA4YmRmY2NlNzIxYTA2MWM3YTI1ZjVlYzQyMWQ5MzIwZDBlYzQ1OSJ9"
$data = YourModel::decryptFind($encrptedId);
Get Encrypted Data
$data = YourModel::where('somewhere','data')->get()->toArray();
- Result Will be :
Array(
[
"id" => "eyJpdiI6IlpxVWtpMGt4dERZbkRcL3hXVTZLKzVRPT0iLCJ2YWx1ZSI6IkhUNzF3MEFsRW1cL2tcLzVTRlZ6QmVaZz09IiwibWFjIjoiZTI5M2JiZTRiNzA2NGVjMTIwNmJhNWZjNjA4YmRmY2NlNzIxYTA2MWM3YTI1ZjVlYzQyMWQ5MzIwZDBlYzQ1OSJ9",
"name" => "Ahmet Oğuz"
]
)
- If You don't Convert to Array, Result Will be :
$data->id = 5,
$data->name = "Ahmet Oğuz"
Disable Encryption Specific Function
- You Should Add Your Function to $hiddenFunctions in Your Model File
- When You Call Your Model in This Function , Result will be :
Call
public function someDefaultFunc2(Request $req){
$data = YourModel::where('somewhere','data')->get()->toArray();
...
}
Result
Array(
[
"id" => 5,
"name" => "Ahmet Oğuz"
]
)
Related Packages
enflow/laravel-database-encryption
A package for automatically encrypting and decrypting Eloquent attributes in Lar...
2,235
1
aes
attribute
attribute encryption
database
database encryption
db
decrypt
decryption
elocrypt
elocryptfive
eloquent
eloquent aes
eloquent encryption
encrypt
encryption
l5
laravel
laravel encryption
laravel5
laravel5 aes
laravel5 encryption
laravel55
laravel55 encryption
laravel56
laravel56 encryption
laravel57
laravel57 encryption
laravel58
laravel58 encryption
laravel6 encryption
model
model encryption
fileinvite-org/laravel-database-encryption
A package for automatically encrypting and decrypting Eloquent attributes in Lar...
10,614
0
aes
attribute
attribute encryption
database
database encryption
db
decrypt
decryption
eloquent
eloquent encryption
encrypt
encryption
l5
laravel
laravel encryption
laravel5
laravel5 encryption
laravel55
laravel55 encryption
laravel56
laravel56 encryption
laravel57
laravel57 encryption
laravel58
laravel58 encryption
laravel6 encryption
laravel60
model
model encryption
Version History
| Version | Released | License |
|---|---|---|
| v1.0.1 | MIT | |
| v1.0.0 | MIT |