PHP code example of bespredel / encryption-form

1. Go to this page and download the library: Download bespredel/encryption-form library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bespredel / encryption-form example snippets


Add the middleware to your Kernel

protected $middleware = [
    // Other middleware
    \Bespredel\EncryptionForm\Middleware\DecryptRequestFields::class
]

Route::middleware('decrypt-form')->group(function () {
    // Your code
})

use Bespredel\EncryptionForm\Services\RequestDecryptor;

$value = $request->input('name'); // Example for 'name' field
$privateKey = config('encryption-form.private_key');

$decryptedValue = RequestDecryptor::decryptValue($value, $privateKey);

$privateKey = config('encryption-form.private_key');

$encryptedData = $request->input('name'); // Example for 'name' field
$decryptedData = null;

$decodedValue = base64_decode((string)str($encryptedData)->after('ENCF:'), true);
openssl_private_decrypt($decodedValue, $decryptedData, $privateKey);

echo $decryptedData; // Output the decrypted value

return [
   'public_key'   => env('ENCRYPTION_FORM_PUBLIC_KEY'),
   'private_key'  => env('ENCRYPTION_FORM_PRIVATE_KEY'),
   'prefix'       => env('ENCRYPTION_FORM_PREFIX', 'ENCF:'),
   'key_rotation' => [
      'enabled'         => env('ENCRYPTION_FORM_KEY_ROTATION_ENABLED', false),
      'cron_expression' => '0 0 * * *',
   ],
];

return [
    ...
   'key_rotation' => [
     'enabled'         => env('ENCRYPTION_FORM_KEY_ROTATION_ENABLED', false),
     'cron_expression' => '0 0 * * *',
   ],
];
bash
   php artisan vendor:publish --tag=encryption-form
   
bash
   php artisan encryption-form:generate-keys
   
bash
php artisan encryption-form:generate-keys
config/encryption-form.php