diff --git a/README.md b/README.md index e82a9e9..d79df2b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Laravel/Lumen MySql AES Encrypt/Decrypt +Total Downloads Latest Stable Version License + Laravel/Lumen database encryption at database side using native AES_DECRYPT and AES_ENCRYPT functions. Automatically encrypt and decrypt fields in your Models. @@ -100,6 +102,20 @@ DB::statement('ALTER TABLE `users` ADD `last_name` VARBINARY(300)'); DB::statement('ALTER TABLE `users` ADD `email` VARBINARY(300)'); DB::statement('ALTER TABLE `users` ADD `telephone` VARBINARY(50)'); ``` +## Implementing encryption for existing data + +For this you can create one command like + +``` +php artisan make:command EncryptionForExistingData +``` + +In this command you fetch existing table or model data without global scope `DecryptSelectScope`. + +You can refer the example, clicking on below Example button: + + + ## License diff --git a/existing_data_encryption.md b/existing_data_encryption.md new file mode 100644 index 0000000..c70aaf7 --- /dev/null +++ b/existing_data_encryption.md @@ -0,0 +1,63 @@ + +## Example of existing data encryption + +```php +error("Model '{$modelName}' not found!"); + + return; + } + + // Instantiate the model + $modelObj = new $modelName; + $modelData = $modelObj->withoutGlobalScopes([DecryptSelectScope::class])->get(); + + foreach ($modelData as $modelRecord) { + $updateModel = $modelName::findOrFail($modelRecord->id); + $fields = $updateModel->encryptable; + foreach ($fields as $field) { + $updateModel->$field = $modelRecord->$field; + } + $updateModel->save(); + } + } + + } +} +```